題庫
00:00

15. Find the Index of the First Occurrence in a String

簡單字串GoogleMicrosoft

Given strings haystack and needle, return the index of the first occurrence of needle in haystack, or -1 if it is not present.

範例 1:

輸入: haystack = "sadbutsad", needle = "sad"
輸出: 0

範例 2:

輸入: haystack = "leetcode", needle = "leeto"
輸出: -1

限制條件:

  • 1 <= haystack.length, needle.length <= 10^4
核心程式碼模式
● 已自動儲存第 1 行,第 1 欄