while(fast != null && fast.next != null){ slow = slow.next; fast = fast.next.next; } ListNodecurr= fast == null ? slow : slow.next, prev = null; //make sure curr is the head of the 2nd part while(curr != null){ //reverse the 2nd part of the nodes ListNodetemp= curr.next; //preserve nodes that after current node curr.next = prev; //add previous node to the current node's next prev = curr; //save previous node curr = temp; //update current node } while(head != null && prev != null){ if(head.val != prev.val) returnfalse; prev = prev.next; head = head.next; } returntrue; } }
You are given an integer array nums that is sorted in non-decreasing order.
Determine if it is possible to split nums into one or more subsequences such that both of the following conditions are true:
Each subsequence is a consecutive increasing sequence (i.e. each integer is exactly one more than the previous integer).
All subsequences have a length of 3** or more**.
Return true* if you can split nums according to the above conditions, or false otherwise*.
A subsequence of an array is a new array that is formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements. (i.e., [1,3,5] is a subsequence of [<u>1</u>,2,<u>3</u>,4,<u>5</u>] while [1,3,2] is not).
Given an array of strings words where each word can be written as a concatenation of the Morse code of each letter.
For example, "cab" can be written as "-.-..--...", which is the concatenation of "-.-.", ".-", and "-...". We will call such a concatenation the transformation of a word.
Return the number of different transformations among all words we have.