https://leetcode.com/problems/length-of-last-word/
int lengthOfLastWord(char* s) {
int ans = 0;
int fans = 0;
for(int i = 0;s[i];i++){
if (s[i] ==' '){fans = ans;ans = 0;while(s[i + 1] == ' '){i++;}}
else ans++;
}
return ans?ans:fans;
}
https://leetcode.com/problems/length-of-last-word/
int lengthOfLastWord(char* s) {
int ans = 0;
int fans = 0;
for(int i = 0;s[i];i++){
if (s[i] ==' '){fans = ans;ans = 0;while(s[i + 1] == ' '){i++;}}
else ans++;
}
return ans?ans:fans;
}