Java Solution


  • 0
    A

    public class Solution {

    public String reverseWords(String s) {
        String res = "";
        
        String[] nonSpace = s.split(" ");
        StringBuffer sb = new StringBuffer();
        for(int x = 0; x < nonSpace.length; x++){
        	sb.append(nonSpace[x]).reverse();
        	res += sb.substring(0);
        	if(x != nonSpace.length - 1)
        		res += " ";
        	sb.delete(0, sb.capacity());
        }
        
        return res;
    }
    

    }


Log in to reply
 

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