Java short and simple solution


  • 0
    V
    public class Solution {
        public String reverseWords(String s) {
            String arr[] = s.split(" ");
            StringBuffer sb = new StringBuffer();
            for(String s1 : arr){
                sb.append(new StringBuffer(s1).reverse().toString());
                sb.append(" ");
            }
            return sb.toString().trim();
        }
    }

Log in to reply
 

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