Java 5 liner with StringBuilder


  • 0
    D
    class Solution {
        public String reverseWords(String s) {
            String output = "";
            String str_array[] = s.split(" ");
            for(int i = 0 ; i < str_array.length; i++)
                output = output + new StringBuilder(str_array[i]).reverse() + " ";
            return output.substring(0, output.length()-1);
        }
    }
    

Log in to reply
 

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