Shortest java solution with stringbuffer


  • 0
    R
    public class Solution {
        public String reverseWords(String s) {
            String[] arr = s.split(" ");
            String ret="";
            for(int i=0;i<arr.length;i++){
                ret+=new StringBuffer(arr[i]).reverse().toString();
                if(i<arr.length-1){
                    ret+=" ";
                }
            }
            return ret;
        }
    }

Log in to reply
 

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