class Solution {
public int lengthOfLastWord(String s) {
int ans = 0, i = s.length() - 1;
for(; i >= 0 && s.charAt(i) == ‘ ‘; i--);
for(; i >= 0 && s.charAt(i) != ‘ ‘; i--)
ans++;
return ans;
}
}
原文:https://www.cnblogs.com/xiafrog/p/14548783.html