image_2022-04-26_18-14-20.png
27.3 KB
#N58. Length of Last Word
problem link
#solution
problem link
#solution
class Solution {
public int lengthOfLastWord(String s) {
int count=0;
for(int i=s.length()-1; i>=0; i--){
if(s.charAt(i)==' ' && count!=0) break;
if(s.charAt(i)!=' ') count++;
}
return count;
}
}