Share my clean and easy to understand java solution


  • 0
    C
    public int lengthOfLastWord(String s) {
    	int length = 0;
    	for (int i = s.length() - 1; i >= 0; i--) {
    		if (s.charAt(i) != ' ') length ++;
    		else if (length != 0) break;
    	}
    	return length;
    }

Log in to reply
 

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