Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
431 B
2
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;
    }
}