-
Notifications
You must be signed in to change notification settings - Fork 17
/
strobogrammatic-number.py
41 lines (30 loc) · 1005 Bytes
/
strobogrammatic-number.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
class Solution:
def isStrobogrammatic(self, num: str) -> bool:
rot_map = {
"0": "0",
"1": "1",
"6": "9",
"8": "8",
"9": "6",
}
left, right = 0, len(num) - 1
while left <= right:
if rot_map.get(num[left], "a") != num[right]:
return False
left, right = left + 1, right - 1
return True
class TestSolution:
def setup(self):
self.sol = Solution()
def test_empty(self):
assert self.sol.isStrobogrammatic("") == True
def test_one2(self):
assert self.sol.isStrobogrammatic("8") == True
def test_one3(self):
assert self.sol.isStrobogrammatic("5") == False
def test_custom1(self):
assert self.sol.isStrobogrammatic("69") == True
def test_custom2(self):
assert self.sol.isStrobogrammatic("82") == False
def test_custom3(self):
assert self.sol.isStrobogrammatic("962") == False