C# Solution


  • 0
    R
    public class Solution {
        public int LengthOfLastWord(string s) {
            if (s.Length == 0)
            {
                return 0;
            }
            int result = 0;
            for (int i = s.Length-1; i >= 0; i--)
            {
                if (s[i] != ' ')
                {
                    result++;
                }
                else if (s[i] == ' ' && result != 0)
                {
                    return result;
                }
            }
            return result;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.