[LintCode] Length of Last Word
public int lengthOfLastWord(String s) { // Write your code here if(s == null || s.length() == 0) return 0; for(int i = s.length()-1; i >=0; i--) { if(s.charAt(i) != ' ') { int res = 0; while(i >=0 && s.charAt(i) != ' ' ){ res++; i--; } return res; } } return 0; }
Leave A Comment