link: https://leetcode.com/problems/reverse-words-in-a-string/
Solution: split + reverse
class Solution {
public String reverseWords(String s) {
if(s.length() == 0) return s;
String[] str = s.split(" ");
String res = " ";
for(int i=str.length - 1; i >= 0; i--) {
if(!str[i].equals("")) {
res = res.concat(str[i]).concat(" ");
}
}
res = res.trim();
return res;
}
}