Java reverse 15ms


  • 0
    A
    public class Solution {
        public String reverseWords(String s) {
            String[] temp = s.split(" ");
            StringBuilder res = new StringBuilder();
            for(int i = 0; i<temp.length;i++){
                res.append(new StringBuilder(temp[i]).reverse());
                if(i == temp.length -1)break;
                res.append(" ");
            }
            return res.toString();
        }
    }
    

Log in to reply
 

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