Java 8: 1 Line Solution


  • 1
    Y
    public class Solution {
        public String reverseWords(String s) {
            return new ArrayList<>(Arrays.asList(s.split(" "))).stream()
                .map(str -> new StringBuilder(str).reverse().toString())
                .collect(Collectors.joining(" "));
        }
    }
    

Log in to reply
 

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