Skip to content

Commit 42a59cf

Browse files
twoSum solution
1 parent 7db8ee3 commit 42a59cf

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

9_Palindrome Number/solution.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#Given an integer x, return true if x is a
2+
# palindrome
3+
# , and false otherwise.
4+
# Example 1:
5+
#
6+
# Input: x = 121
7+
# Output: true
8+
# Explanation: 121 reads as 121 from left to right and from right to left.
9+
# Example 2:
10+
#
11+
# Input: x = -121
12+
# Output: false
13+
# Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
14+
# Example 3:
15+
#
16+
# Input: x = 10
17+
# Output: false
18+
# Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
19+
#
20+
21+
x = 121
22+
23+
24+
def a(number) -> bool:
25+
linum = [i for i in str(number)]
26+
27+
left, right = 0, len(linum) - 1
28+
29+
while left < right:
30+
if linum[left] == linum[right]:
31+
left += 1
32+
right -= 1
33+
34+
else:
35+
return False
36+
37+
return True
38+
39+
40+
print(a(x))

0 commit comments

Comments
 (0)