length_of_last_word.py 328 B

1234567891011121314151617
  1. import pytest
  2. def lengthOfLastWord(s: str) -> int:
  3. s = s.split()[-1]
  4. return len(s)
  5. @pytest.mark.parametrize(
  6. "s, expect",
  7. [
  8. ("Hello World", 5),
  9. (" fly me to the moon ", 4),
  10. ("luffy is still joyboy", 6)
  11. ]
  12. )
  13. def test_cases(s, expect):
  14. assert lengthOfLastWord(s) == expect