One line python solution (accepted)


  • 0
    Z
    class Solution(object):
        def lengthOfLastWord(self, s):
            """
            :type s: str
            :rtype: int
            """
            return len(s.rsplit(None, 1)[-1]) if s and s.strip() else 0
    

Log in to reply
 

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