My C 1ms solution


  • 0
    C
    int lengthOfLastWord (const char *s) {
    if (s[0] == '\0') return 0;
    while (true)
    {
    	const char* ptr = s;
    	s += strcspn (s, " \t");
    	s += strspn (s, " \t");
    	if (s[0] == '\0')
    		return strcspn (ptr, " \t");
    }
    return 0;}

Log in to reply
 

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