public class Solution {
public int lengthOfLastWord(String s) {
char[] a = s.toCharArray();
int count = 0;
for(int i = a.length-1 ; i > -1;i--){
if(a[i] != ' '){
count++;
if(i > 1){
if(a[i-1] == ' '){
break;
}
}
}
}
return count;
}
}
主要就是確定兩端都不是空格!小白筆記----------------leetcode 58. Length of Last Word
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.