Offer58I.翻转单词顺序/Solution.java
<reponame>codeSu97/SwordToOfferclass Solution {
    public String reverseWords(String s) {
        if (s.length() == 0) return s;
        s = s.trim();
        StringBuffer res = new StringBuffer();

        int i = s.length() - 1, j = i;

        while (i >= 0) {
            while (i >= 0 && s.charAt(i) != ' ') i--;
            res.append(s.substring(i + 1, j + 1) + " ");
            while (i >= 0 && s.charAt(i) == ' ') {
                i--;
                j = i;
            }
        }

        return res.toString().trim();
    }
}