Skip to content

Commit

Permalink
Create confusing-number.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Jun 2, 2019
1 parent 5938ea3 commit 22536fe
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Python/confusing-number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Time: O(logn)
# Space: O(1)

class Solution(object):
def confusingNumber(self, N):
"""
:type N: int
:rtype: bool
"""
lookup = {"0":"0", "1":"1", "6":"9", "8":"8", "9":"6"}

S = str(N)
result = []
for i in xrange(len(S)):
if S[i] not in lookup:
return False
for i in xrange((len(S)+1)//2):
if S[i] != lookup[S[-(i+1)]]:
return True
return False

0 comments on commit 22536fe

Please sign in to comment.