2019年1月24日星期四

[LeetCode] 58. Length of Last Word

lol,工作很繁重,脑子不是很清楚,只能拿一道简单到逆天的题目充数了 ╮( ̄▽ ̄)╭ 
class Solution {
public int lengthOfLastWord(String s) {
int end = s.length() - 1;
while (end >= 0 && s.charAt(end) == ' ') {
end--;
}
int start = end;
while (start >= 0 && s.charAt(start) != ' ') {
start--;
}
if (end >= 0) {
return end - start;
}
return 0;
}
}

没有评论:

发表评论