Find the First Match

Substring search is used in editors, logs, and filters when you need to know where a piece of text first appears. The function contain_string receives two strings, haystack and needle. Return the zero-based index of the first occurrence of needle inside haystack. If it is not found, return -1, and if needle is empty, return 0.

Примеры

Ввод
["mississippi", "issipi"]
Вывод
-1
Ввод
["Hello World", ""]
Вывод
0
Ввод
["hello", "ll"]
Вывод
2

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

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

Теги

stringstwo-pointers
PostgreSQLv16

Le résultat de l'exécution du code s'affichera ici

Visible tests
1
Input
"mississippi", "issipi"
Expected-1
2
Input
"Hello World", ""
Expected0
3
Input
"hello", "ll"
Expected2
4
Input
"abc", "c"
Expected2
5
Input
"hello", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Expected-1
6
Input
"hello", ""
Expected0
Focus radio
Paused · SomaFM · Fluid