Monday, November 6, 2017

58. Length of Last Word

class Solution:
    def lengthOfLastWord(self, s):
        """
        :type s: str
        :rtype: int
        """
        new_string = s
        new_string = new_string.lower()
        new_list = new_string.split()
        try:
            return len(new_list[-1])
        except:
            return 0

No comments:

Post a Comment