Why nobody use String.split?


  • 1
    Y

    I just try to use the split method for this problem and be accepted.

            if(res.length == 0){
                return 0;
            }
            int i = res.length;
            return res[i - 1].length();
    
    I don't know if it has some defects.

  • 1
    H

    Excellent Question!!!


  • 1
    Y
    String[] res = s.split(" ");
            if(res.length == 0){
                return 0;
            }
            int i = res.length;
            return res[i - 1].length();
    
    It should be like this

Log in to reply
 

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