LeetCode 28. Find the Index of the First Occurrence in a String

October 31, 2024

This was an easy problem.

Solution

1class Solution:
2 def strStr(self, haystack: str, needle: str) -> int:
3 for j in range(len(haystack)):
4 if haystack[j:j + len(needle)] == needle:
5 return j
6 return -1

O(n) = n

LeetCode 6. Zigzag Conversion

LeetCode 68. Text Justification