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
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inVisible tests
1
Input
"this is my text", "is"Expected
22
Input
"aaaa", "aa"Expected
23
Input
"abc", ""Expected
04
Input
"aaaa", "a"Expected
45
Input
"Hello, World!", "si"Expected
06
Input
" ", ""Expected
0Focus radio
Paused · SomaFM · Fluid