public int lengthOfLastWord(String s) {
        s = s.trim();
        if(s.isEmpty()) return 0;
        int i = s.length() - 1;
        int len = 0;
        while(i >= 0 && s.charAt(i) != ' '){
            i--;
            len++;
        }
        return len;
    }