Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.
The input string does not contain leading or trailing spaces and the words are always separated by a single space.
For example,
Given s = “The sky is blue“,
return "Blue is the sky“.
Could you do it in-place without allocating extra space?
This problem is related to Rotate Array (https://blog.jing.do/4727 ) is one solution.
public class Solution { public void reverseWords(char[] s) { rev(s,0,s.length-1); int pos = 0; for(int i =0;i This websiteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:
Original author:Jake Tao,source:"LeetCode – 186. Reverse Words in a String II"