First Substring Match

Substring search is a basic operation when checking messages, logs, and commands. Given strings haystack and needle, find the index where needle first appears inside haystack. If the substring is not found, return -1.

Примеры

Ввод
"sadbutsad", "sad"
Вывод
0
Ввод
"leetcode", "leeto"
Вывод
-1
Ввод
"hello", "ll"
Вывод
2

Нужно реализовать

def str_str(haystack: str, needle: str) -> int:

Теги

stringstwo-pointers
PostgreSQLv16

Tutaj pojawi się wynik wykonania kodu

Visible tests
1
Input
"sadbutsad", "sad"
Expected0
2
Input
"leetcode", "leeto"
Expected-1
3
Input
"hello", "ll"
Expected2
4
Input
"abc", ""
Expected0
5
Input
"a", "a"
Expected0
6
Input
"Hello, World!", "sad"
Expected-1
Focus radio
Paused · SomaFM · Fluid