4 lines simple Java solution


  • 0
    J
    public class Solution {
        public int lengthOfLastWord(String s) {
            String[] ss = s.split(" ");
            int len = ss.length;
            if(len == 0) return 0;
            return ss[len - 1].length();
        }
    }

Log in to reply
 

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