-
Notifications
You must be signed in to change notification settings - Fork 464
Expand file tree
/
Copy path788_Rotated_Digits.py
More file actions
31 lines (30 loc) · 1.05 KB
/
788_Rotated_Digits.py
File metadata and controls
31 lines (30 loc) · 1.05 KB
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
class Solution(object):
def rotatedDigits(self, N):
"""
:type N: int
:rtype: int
"""
count = 0
for i in range(N + 1):
numStr = str(i)
if ("3" in numStr) or ("4" in numStr) or ("7" in numStr):
continue
numStrRotated = ""
for digit in numStr:
if digit == "0":
numStrRotated = numStrRotated + "0"
elif digit == "1":
numStrRotated = numStrRotated + "1"
elif digit == "2":
numStrRotated = numStrRotated + "5"
elif digit == "5":
numStrRotated = numStrRotated + "2"
elif digit == "6":
numStrRotated = numStrRotated + "9"
elif digit == "8":
numStrRotated = numStrRotated + "8"
elif digit == "9":
numStrRotated = numStrRotated + "6"
if numStr != numStrRotated:
count += 1
return count