java solution use StringBuilder


  • 0
    R

    public String reverseWords(String s) {
    String arr [] = s.split(" ");
    StringBuilder result = new StringBuilder();
    for(String str : arr){
    StringBuilder a = new StringBuilder(str);
    result.append(a.reverse());
    result.append(" ");
    }
    return result.substring(0,result.length()-1);
    }


Log in to reply
 

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