@@ -0,0 +1,981 @@
+package fundamentals.string.manipulate.lc186_reversewordsinastring2;%0A%0A/**%0A * Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.%0A * The input string does not contain leading or trailing spaces and the words are always separated by a single space.%0A */%0Apublic class Solution %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        char%5B%5D s = %22the sky is blue%22.toCharArray();%0A        new Solution().reverseWords(s);%0A        System.out.println(String.valueOf(s));%0A    %7D%0A%0A    public void reverseWords(char%5B%5D s) %7B%0A        int n = s.length;%0A        swap(s, 0, n - 1);%0A        for (int i = 0, j = 0; j %3C= n; j++) %7B%0A            if (j == n %7C%7C s%5Bj%5D == ' ') %7B%0A                swap(s, i, j - 1);%0A                i = j + 1;%0A            %7D%0A        %7D%0A    %7D%0A%0A    private void swap(char%5B%5D s, int i, int j) %7B%0A        for (; i %3C j; i++, j--) %7B%0A            char tmp = s%5Bi%5D;%0A            s%5Bi%5D = s%5Bj%5D;%0A            s%5Bj%5D = tmp;%0A        %7D%0A    %7D%0A%0A%7D%0A

reverse words in a string II