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