# Solutions for String pattern matching

• @Charles, submitted in Python 3, achived 100% score
``````# Complete the substrCount function below.
def solve(n, s):
count = n
for x in range(n):
y = x
while y < n - 1:
y += 1
if s[x] == s[y]:
count += 1
else:
if s[x:y] == s[y+1:2*y-x+1]:
count += 1
break

return count
``````
• @Zafir, submitted in Python 2, achived 100% score
``````# Complete the substrCount function below.
def solve(n, s):
count = n
for x in range(n):
y = x
while y < n - 1:
y += 1
if s[x] == s[y]:
count += 1
else:
if s[x:y] == s[y+1:2*y-x+1]:
count += 1
break

return count

``````
• @Zafir, submitted in Python 2, achived 100% score
``````# Complete the substrCount function below.
def solve(n, s):
count = n
for x in range(n):
y = x
while y < n - 1:
y += 1
if s[x] == s[y]:
count += 1
else:
if s[x:y] == s[y+1:2*y-x+1]:
count += 1
break

return count

``````
• @jacob, submitted in Python 2, achived 100% score
``````# Complete the substrCount function below.
def solve(n, s):
count = n
for x in range(n):
y = x
while y < n - 1:
y += 1
if s[x] == s[y]:
count += 1
else:
if s[x:y] == s[y+1:2*y-x+1]:
count += 1
break

return count

``````
• @jacob, submitted in Python 3, achived 100% score
``````# Complete the substrCount function below.
def solve(n, s):
count = n
for x in range(n):
y = x
while y < n - 1:
y += 1
if s[x] == s[y]:
count += 1
else:
if s[x:y] == s[y+1:2*y-x+1]:
count += 1
break

return count
``````