Only one array


  • 0
    D

    public String reverseWords(String s) {

    	String[] strarr = s.split(" ");
    	s = "";
    	for(int i = 0;i < strarr.length;i++){
    		StringBuffer sb = new StringBuffer();
                    sb.append(strarr[i]);
                    strarr[i] = String.valueOf(sb.reverse());
                    s += i == strarr.length -1?strarr[i] : strarr[i] + " ";
    	}
            return s;
    }

Log in to reply
 

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