Nothing Fancy - Straight Java StringBuilder


  • 0
        public String reverseWords(String s) {
            String[] strs = s.split(" ");
            StringBuilder res = new StringBuilder();
            for (String str : strs) {
                StringBuilder sb = new StringBuilder(str); 
                res.append(sb.reverse()).append(" "); 
            }
            return res.toString().trim(); 
        }

Log in to reply
 

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