My solution but failed but I cannot figure out why

  • 1
    public class Solution {
        public String reverseWords(String s) {
            if(s.trim().equals("")) return s;
            String[] strs = s.split(" +");
            String ret="";
            for(int i=strs.length-1; i>=0; i--){
                if(i==0) ret=ret+strs[i];
                else ret=ret+strs[i]+" ";
            return ret;

    can somebody give me some hint?/

Log in to reply

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