Easy Java Solution


  • 0
    public class Solution {
        public String reverseWords(String s) {
            if (s == null || s.length() == 0) return "";
            String[] arr = s.split(" ");
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < arr.length; i++) {
                sb.append(reverse(arr[i])).append(" ");
            }
            return sb.substring(0, sb.length() - 1);
        }
        private String reverse(String s) {
            return new StringBuilder(s).reverse().toString();
        }
    }
    

  • 0
    This post is deleted!

Log in to reply
 

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