c# - cheating with string split :D


  • 0
    R
    public int LengthOfLastWord(string s)
    {
    		if(string.IsNullOrEmpty(s) || s.Split(new char[] { ' '},StringSplitOptions.RemoveEmptyEntries).Count()==0)
    		return 0;
    		
    		var result =  s.Split(new char[] { ' '}, StringSplitOptions.RemoveEmptyEntries).ToArray();
    		return result[result.Length-1].Length;
    }

Log in to reply
 

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