java via in-build api


  • 0
    public class Solution {
        public String reverseWords(String s) {
            String[] words = s.split(" ");
            StringBuilder result = new StringBuilder();
            for(int i = 0; i < words.length; i++){
            	StringBuilder sb = new StringBuilder(words[i]);
            	result.append(sb.reverse().toString() + " ");
            }
            return result.replace(result.length() - 1, result.length(), "").toString();
        }
    }
    

Log in to reply
 

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