We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Nice solution! I prefer a forward traversal (yours is reverse). Here's my version of your code:
defcount_substring(string,sub_string):counter=0len_str=len(string)len_sub=len(sub_string)#looping over a set of numbers starting at 0 through the length of string exclusiveforiinrange(0,len_str):#if string's contents ranging from i through i plus the length of the sub_string#is equal to the sub_stringifstring[i:i+len_sub]==sub_string:#then increment the countercounter+=1returncounter
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Minion Game
You are viewing a single comment's thread. Return to all comments →
Nice solution! I prefer a forward traversal (yours is reverse). Here's my version of your code: