public String reverseWords(String s) {
        if (s == null) return null;
        String result = "";
        String word = "";
        for (int i = 0; i < s.length(); ++i) {
            char ch = s.charAt(i);
            if (ch == ' ' && word.isEmpty()) continue;
            else if (ch == ' ' && !word.isEmpty()) {
                result = word + " " + result;
                word = "";
            }
            else if (ch != ' ') {
                word += ch;
            }
        }
        if (!word.isEmpty()) result = word + " " + result;
        if (!result.isEmpty()) result = result.substring(0, result.length() - 1);
        return result;
    }