728x90
Above is the link to the problem.
Problem
Given two strings variables "needle" and "haystack",
return the index of the first occurrence of "needle" in "haystack",
or -1 if "needle" is not part of "haystack".
Example 1
Input: haystack = "sadbutsad", needle = "sad"
Output: 0
Explanation: "sad" occurs at indexes 0 and 6.
We are finding the first occurrence.
So we return 0.
Example 2
Input: haystack = "leetcode", needle = "leeto"
Output: -1
Explanation: "leeto" did not occur in "leetcode", so we return -1.
Code
This code gets the top 1.08% of time complexity and uses 13.8MB of memory.
728x90
반응형
'Code > LeetCode' 카테고리의 다른 글
[LeetCode] 2187. Minimum Time to Complete Trips (Medium/Python) (0) | 2023.03.08 |
---|---|
[LeetCode] 202. Happy Number (Easy/Python) (0) | 2023.03.05 |
[LeetCode] 191. Number of 1 Bits (Easy/Python) (0) | 2023.03.02 |
[LeetCode] 190. Reverse Bits (Easy/Python) (0) | 2023.01.15 |
[LeetCode] 134. Gas Station (Medium/Python) (0) | 2023.01.14 |