很拙劣的写法。
class Solution:
def rotatedDigits(self, N: int) -> int:
# 除了这些以外其他的数字旋转以后都不再是有效的数字。
# 23 53 24 54 都不算
d = {"0": 0, "1": 1, "2": 5, "5": 2, "6": 9, "8": 8, "9": 6}
ret = 0
for i in range(1, N+1):
s = str(i)
if all(j in d for j in s):
t = list(s).copy()
rot = ""
for j in s:
if str(j) in d:
j = d[str(j)]
rot += str(j)
if rot != ''.join(t):
# print(''.join(t), rot)
ret += 1
return ret
网友评论