class Solution {
public int lengthOfLastWord(String s) {
for(int i=s.length()-1; i>=0; i--) {
if(s.charAt(i) == ' '){
} else {
l++;
if(s.charAt(i-1) == ' ') {
return l;
}
}
}
return l;
}
}
https://leetcode.com/problems/length-of-last-word/description/
I was doing the above leetcode problem and i think i got it correct i tested for some inputs and it was just working fine but when i submitted it on leetcode it only passed 3 testcases out of 59. 🙁
Can someone tell me how to fix this
4