My 0ms Java solution may help u


  • 1
    public class Solution {
        public int lengthOfLastWord(String s) {
            s = s.trim();
    		if (s.equals(""))
    			return 0;
    		int res = 0;
    		for (int i = s.length() - 1; i > -1 && s.charAt(i) != ' '; ++res, --i);
    		return res;
        }
    }

Log in to reply
 

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