Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string = "aaaaa"
- substring = "aa"
- total = 0
- i = 0
- j = 0
- oldIndex = 0
- # len(string) -> string.length
- while i < len(string):
- # string[i] -> string.charAt(i)
- if string[i] == substring[j]:
- if j == 0:
- oldIndex = i
- if j == len(substring) - 1:
- total = total + 1
- j = 0
- i = oldIndex
- else:
- j = j + 1
- elif j != 0:
- i = oldIndex
- j = 0
- i = i + 1
- print total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement