-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1461.py
51 lines (41 loc) · 1.16 KB
/
1461.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import unittest
class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
target = pow(2, k)
count = 0
hash = [False] * target
for i in range(len(s) - k + 1):
idx = int(s[i:i+k], 2)
if not hash[idx]:
hash[idx] = True
count += 1
if count == target:
return True
return False
class SolutionTest(unittest.TestCase):
solution = Solution()
def test_1(self):
s = "00110110"
k = 2
actual = self.solution.hasAllCodes(s, k)
self.assertTrue(actual)
def test_2(self):
s = "00110"
k = 2
actual = self.solution.hasAllCodes(s, k)
self.assertTrue(actual)
def test_3(self):
s = "0110"
k = 1
actual = self.solution.hasAllCodes(s, k)
self.assertTrue(actual)
def test_4(self):
s = "0110"
k = 2
actual = self.solution.hasAllCodes(s, k)
self.assertFalse(actual)
def test_5(self):
s = "0000000001011100"
k = 4
actual = self.solution.hasAllCodes(s, k)
self.assertFalse(actual)