From 266227e872e278dc69c5f1deada3832ee472ec29 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 21 Jan 2025 04:33:24 -0600 Subject: [PATCH] adding length of last word --- .../top_150_questions_round_13/length_of_last_word.py | 10 ++++++++++ .../test_length_of_last_word_round_13.py | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_13/length_of_last_word.py create mode 100644 tests/test_150_questions_round_13/test_length_of_last_word_round_13.py diff --git a/src/my_project/interviews/top_150_questions_round_13/length_of_last_word.py b/src/my_project/interviews/top_150_questions_round_13/length_of_last_word.py new file mode 100644 index 00000000..8014be03 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_13/length_of_last_word.py @@ -0,0 +1,10 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def lengthOfLastWord(self, s: str) -> int: + + lst_s = s.split() + + return len(lst_s[-1]) + diff --git a/tests/test_150_questions_round_13/test_length_of_last_word_round_13.py b/tests/test_150_questions_round_13/test_length_of_last_word_round_13.py new file mode 100644 index 00000000..c2cb6cbd --- /dev/null +++ b/tests/test_150_questions_round_13/test_length_of_last_word_round_13.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_13\ +.length_of_last_word import Solution + +class LengthLastWordTestCase(unittest.TestCase): + + def test_length_last_word(self): + solution = Solution() + output = solution.lengthOfLastWord(s="Hello World") + target = 5 + self.assertEqual(output, target) \ No newline at end of file