1 public class Solution {
2 public int lengthOfLastWord(String s) {
3 // IMPORTANT: Please reset any member data you declared, as
4 // the same Solution instance will be reused for each test case.
5 if(s == null)
6 return 0;
7 char[] mychar = s.trim().toCharArray();
8 int count = 0;
9 for(int i=0; i<mychar.length; i++)
10 {
11 char tmp = mychar[i];
12 if(tmp == ' ')
13 count = 0;
14 else if((tmp >= 'A' && tmp <= 'Z')||(tmp >= 'a' && tmp <= 'z'))
15 count++;
16 else{
17 count = 0;
18 do{i++;}while(mychar[i] != ' '&&i<mychar.length);
19 }
20 }
21 return count;
22 }
23 }