diff --git a/28. Find the Index of the First Occurrence in a String/28.py b/28. Find the Index of the First Occurrence in a String/28.py new file mode 100644 index 0000000..e7a4831 --- /dev/null +++ b/28. Find the Index of the First Occurrence in a String/28.py @@ -0,0 +1,26 @@ +test_cases = [ + ["sadbutsad", "sad"], + ["leetcode", "leeto"] +] + +expected_results = [ + 0, + -1 +] + + +class Solution: + def strStr(self, haystack: str, needle: str) -> int: + return haystack.find(needle) + + +# Testing +for i in range(0, len(test_cases)): + result = Solution.strStr( + Solution, test_cases[i][0], test_cases[i][1]) + if result == expected_results[i]: + print(f"==Test case {i+1} was valid") + print(f"✔️ Got '{result}', expected {expected_results[i]}") + else: + print(f"==Test case {i+1} was INVALID") + print(f"❌ Got '{result}', expected {expected_results[i]}")