@@ -0,0 +1,1216 @@
+/***%0A * Given an input string, reverse the string word by word.%0A *%0A * For example,%0A * Given s = %22the sky is blue%22,%0A * return %22blue is sky the%22.%0A *%0A * Clarification:%0A *   What constitutes a word?%0A *      A sequence of non-space characters constitutes a word.%0A *   Could the input string contain leading or trailing spaces?%0A *      Yes. However, your reversed string should not contain leading or trailing spaces.%0A *   How about multiple spaces between two words?%0A *      Reduce them to a single space in the reversed string.%0A */%0Apublic class Solution %7B%0A    // Solution 1: Recursive O(n) O(n%5E2)%0A    public String reverseWords(String s) %7B%0A        char charArr%5B%5D = s.toCharArray();%0A        for (int i = 0; i %3C charArr.length; i++) %7B%0A            if (charArr%5Bi%5D == ' ')%0A                return Reverse(s.substring(i + 1)) + s.substring(0, i) + %22 %22;%0A        %7D%0A        return s + %22 %22;%0A    %7D%0A%0A    // Solution 2: Using split, regex O(n)%0A    public String reverseWords(String s) %7B%0A        StringBuilder ret = new StringBuilder();%0A        String%5B%5D words = s.split(%22%5C%5Cs+%22);%0A        for (int i = words.length - 1; i %3E= 0; i--) %7B%0A            ret.append(words%5Bi%5D).append(' ');%0A        %7D%0A        return ret.toString().trim();%0A    %7D%0A%7D%0A

add ReverseWordsinaString.java