4 Line Java Solution


  • 0
    T
    public class Solution {
        public String reverseWords(String s) {
            String[] sentence = s.split(" ");
            for (int i = 0; i < sentence.length; i++)
                sentence[i] = new StringBuilder(sentence[i]).reverse().toString();
            return String.join(" ", sentence);
      }
    }
    

Log in to reply
 

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