Substring Count

Given a string s and a substring sub, count how many times sub appears in s using non-overlapping matches only. For example, in aaaa, the substring aa counts as two matches, not three. If sub is empty, return 0.

Примеры

Ввод
"this is my text", "is"
Вывод
2
Ввод
"aaaa", "aa"
Вывод
2
Ввод
"abc", ""
Вывод
0

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

def count_substring(s: str, sub: str) -> int:

Теги

strings
PostgreSQLv16

Hier erscheint das Ergebnis der Codeausführung

Visible tests
1
Input
"this is my text", "is"
Expected2
2
Input
"aaaa", "aa"
Expected2
3
Input
"abc", ""
Expected0
4
Input
"aaaa", "a"
Expected4
5
Input
"Hello, World!", "si"
Expected0
6
Input
" ", ""
Expected0
Focus radio
Paused · SomaFM · Fluid