4-line Java Solution


  • 0
    2

    not sure if StringBuilder is allowed, but here it is

        public String reverseWords(String s) {
            String[] splitted = s.split("\\s+");
            
            for(int i=0;i<splitted.length;i++){
                splitted[i]=new StringBuilder(splitted[i]).reverse().toString();
            }
            
            return String.join(" ", splitted);
        }
    
    

Log in to reply
 

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