Java solution using split and join


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

Log in to reply
 

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