Java Solution


  • 0
    U
    class Solution {
        public String reverseWords(String s) {
            
            if(s.length() == 0)
              return "";
            
            StringBuilder sb = new StringBuilder();
            
            String[] str = s.split("\\s+");
            
            for(int i = 0;i<str.length; i++){
               sb.append(new StringBuilder(str[i]).reverse().toString()).append(" ");
            }
            
            return sb.toString().trim();
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.