package leetcode;

/**
 * https://oj.leetcode.com/problems/reverse-words-in-a-string/
 */
public class Problem151 {
    public String reverseWords(String s) {
        String[] strs = s.trim().split("\\s+");
        StringBuilder sb = new StringBuilder();
        for (int i = strs.length-1; i >= 0; i--) {
            sb.append(strs[i]);
            if (i > 0) {
                sb.append(' ');
            }
        }
        return sb.toString();
    }
    
    public static void main(String[] args) {
        Problem151 prob = new Problem151();
        System.out.println(prob.reverseWords("the sky is blue"));
        System.out.println(prob.reverseWords("hello world"));
    }
}

@@ -452,234 +452,6 @@
   %7D%0A
-    %0A    public static void main(String%5B%5D args) %7B%0A        Problem151 prob = new Problem151();%0A        System.out.println(prob.reverseWords(%22the sky is blue%22));%0A        System.out.println(prob.reverseWords(%22hello world%22));%0A    %7D%0A
 %7D%0A

Update problem 151