今日随感:今天小组内第一次开会,感觉小组内其他外国朋友都挺友好,大家能够很好的聊在一起,讨论时也很积极,觉得这样的氛围对做项目特别有帮助。
题目图片 代码public class Solution {
public int LengthOfLastWord(string s) {
int j = s.Length - 1;
int ans = 0;
if(s[j] == ' '){
while(j >= 0 && s[j] == ' '){
j--;
}
}
while(j >= 0 && s[j] != ' '){
ans++;
j--;
}
return ans;
}
}
while循环中要把判断是否越界放在第一个,如果放在与逻辑的后面,就会出现数组越界的错误


