1 liner Python.. beats 90% of Python solutions


  • 1
    S
    return (len(s.split()[-1]) if len(s.split()) >= 1 else 0)
    

  • 1
    W

    You call .split() twice in there - brings execution speed down. I had a very similar solution - split it out from one line and it beats 98% :)

    words = s.split()
    
    if not words:
        return 0
    
    return len(words[-1])

Log in to reply
 

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