Problem Link
Detailed Step-by-Step Explanation
Solution
class Solution {
public int lengthOfLastWord(String s) {
int n = s.length();
int count = 0;
for(int i=n-1; i>=0; i--) {
if(s.charAt(i) != ' ') {
count++;
}
else {
if(count > 0) {
return count;
}
}
}
return count;
}
}

Top comments (0)