+ 2
how to count total number of occurrences of the substring in the original string
ABCDCDC CDC. O/P=2
4 ответов
+ 10
Hy SHUBHAM KUMAR YADAV
U can link your code to share what u have done so far , to get better help from community
● here is some idea : move in String1 from character at index 0 to character at index (String1.length - (String2.length-1)) & take out (string2.length) letters out each time & compare it with String2
//str2.length to (str2.length-1) ... correction by Louis
//sorry for mistake there.
+ 5
Please show your attempt.
+ 2
In Python this is very simple: use the count method of string!
EDIT: I stand corrected - str.count doesn't recognize overlaps!
+ 2
thanks Gaurav :
its done by your logic