-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path9.py
70 lines (67 loc) · 2.23 KB
/
9.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
__________________________________________________________________________________________________
76ms
class Solution:
def isPalindrome(self, x: int) -> bool:
str_x=str(x)
return str_x==str_x[::-1]
__________________________________________________________________________________________________
80ms
class Solution:
def isPalindrome(self, x: int) -> bool:
x = str(x)
if len(x) % 2 == 0:
if x[:len(x)//2] == x[len(x)//2:][::-1]:
return True
else:
return False
elif x[len(x)//2 + 1:] == x[:len(x)//2][::-1]:
return True
else:
return False
__________________________________________________________________________________________________
84ms
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
strValue = list(str(x))
left, right = 0, len(strValue) - 1
while left <= right:
if strValue[left] != strValue[right]:
return False
left += 1
right -= 1
return True
__________________________________________________________________________________________________
12392 kb
class Solution:
def isPalindrome(self, x: 'int') -> 'bool':
if x < 0:
return False
elif x == 0:
return True
elif x%10 == 0:
return False
else:
def rev(x):
reverse = 0
temp = x
while temp != 0:
reverse = reverse*10 + temp%10
temp = temp//10
return reverse
print(x)
print(rev(x))
return x == rev(x)
__________________________________________________________________________________________________
12416 kb
class Solution:
def isPalindrome(self, x: 'int') -> 'bool':
string_x = str(x)
if string_x[0] == '-':
return False
else:
reversed_string_x = string_x[::-1]
reversed_x = int(reversed_string_x)
return x == reversed_x
__________________________________________________________________________________________________