Skip to content

Commit 06a6e01

Browse files
authored
Create detect-pattern-of-length-m-repeated-k-or-more-times.py
1 parent 4e0f691 commit 06a6e01

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def containsPattern(self, arr, m, k):
6+
"""
7+
:type arr: List[int]
8+
:type m: int
9+
:type k: int
10+
:rtype: bool
11+
"""
12+
cnt = 0
13+
for i in xrange(len(arr)-m):
14+
if arr[i] != arr[i+m]:
15+
cnt = 0
16+
continue
17+
cnt += 1
18+
if cnt == (k-1)*m:
19+
return True
20+
return False

0 commit comments

Comments
 (0)