Untitled
unknown
plain_text
2 years ago
431 B
8
Indexable
public class Solution {
public int LengthOfLastWord(string s)
{
Stack<char> stc = new Stack<char>();
int j=s.Length;
int n=0;
if(s == null || s.Length == 0)
{
return 0;
}
for(int i=j-1;i>=0;i--)
{
if(s[i] != ' ')
{
stc.Push(s[i]);
n++;
}
else if(n>0)
{
return n;
}
};
return n;
}
}
Editor is loading...