My LeetCode grinding. Trying to do a problem a day.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516
  1. class Solution:
  2. def lengthOfLastWord(self, s: str) -> int:
  3. s = s.strip()
  4. for i in range(len(s) - 1, -1, -1):
  5. if s[i] == " ":
  6. print("Found space at", i, len(s) - 1)
  7. if i == len(s) - 1:
  8. return 0
  9. else:
  10. return len(s[i+1:])
  11. return len(s)
  12. s = Solution()
  13. print("Expected: 0")
  14. print("Got:", s.lengthOfLastWord("Test"))