Java Solution, easy to understand


  • 0
    J
    public class Solution {
        public String reverseWords(String s) {
            StringBuilder result = new StringBuilder("");
            String[] list  = s.split(" ");
            for(String temp : list){
                StringBuilder reverser = new StringBuilder(temp);
                result.append(" "+reverser.reverse());
            }
            return result.toString().trim();
        }
    }
    

Log in to reply
 

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