标签:blog io java ar for div sp log on
public class Solution {
public int lengthOfLastWord(String s) {
int lastLength = 0;
int nowLength = 0;
for (int i=0; i<s.length(); i++) {
if(s.charAt(i)==‘ ‘) {
if (nowLength!=0) lastLength=nowLength;
nowLength=0;
}
else
nowLength++;
}
if (nowLength!=0) lastLength = nowLength;
return lastLength;
}
}
[LeetCode] Length of Last Word
标签:blog io java ar for div sp log on
原文地址:http://www.cnblogs.com/yuhaos/p/3967434.html