Given an input character array, reverse the array word by word. A word is defined as a sequence of non-space characters.
The input character array does not contain leading or trailing spaces and the words are always separated by a single space.
Example
Input: [“t”,”h”,”e”,” “,”s”,”k”,”y”,” “,”i”,”s”,” “,”b”,”l”,”u”,”e”]
Output: [“b”,”l”,”u”,”e”,” “,”i”,”s”,” “,”s”,”k”,”y”,” “,”t”,”h”,”e”]
Challenge
Could you do it in-place without allocating extra space?
Code
1 | public char[] reverseWords(char[] str) { |