+ 2

how to count total number of occurrences of the substring in the original string

ABCDCDC CDC. O/P=2

6th Jan 2019, 5:14 PM
Shubham Yadav
Shubham Yadav - avatar
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.
6th Jan 2019, 5:42 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
Please show your attempt.
6th Jan 2019, 5:20 PM
Diego
Diego - avatar
+ 2
In Python this is very simple: use the count method of string! EDIT: I stand corrected - str.count doesn't recognize overlaps!
6th Jan 2019, 5:52 PM
HonFu
HonFu - avatar
+ 2
thanks Gaurav : its done by your logic
6th Jan 2019, 9:10 PM
Shubham Yadav
Shubham Yadav - avatar