@@ -0,0 +1,768 @@
+package fundamentals.string.manipulate.lc557_reversewordsinastring3;%0A%0A/**%0A * Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.%0A */%0Apublic class Solution %7B%0A%0A    public String reverseWords(String s) %7B%0A        int n = s.length();%0A        char%5B%5D ch = s.toCharArray();%0A        for (int i = 0, j = 0; j %3C= n; j++) %7B%0A            if (j == n %7C%7C s.charAt(j) == ' ') %7B%0A                rev(ch, i, j - 1);%0A                i = j + 1;%0A            %7D%0A        %7D%0A        return String.valueOf(ch);%0A    %7D%0A%0A    private void rev(char%5B%5D ch, int i, int j) %7B%0A        for (; i %3C j; i++, j--) %7B%0A            char tmp = ch%5Bi%5D;%0A            ch%5Bi%5D = ch%5Bj%5D;%0A            ch%5Bj%5D = tmp;%0A        %7D%0A    %7D%0A%0A%7D%0A

reverse words in a string III