class Solution { public String reverseWords(String s) { s = s.trim(); String[] str = s.split(" "); StringBuilder sb = new StringBuilder(); int len = str.length; for(int i = len-1;i>=0;i--){ if(!str[i].equals("")){ if(i == 0){ sb.append(str[i]); }else{ sb.append(str[i]).append(" "); } } } return sb.toString(); } }