Skip to content

Commit f8d49e7

Browse files
authored
Create 9. Palindrome Number
1 parent 724a9a1 commit f8d49e7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

9. Palindrome Number

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#### I believed that is not a great solution for this problem because of if statement in length. However, it is still reliable one.
2+
3+
class Solution(object):
4+
def isPalindrome(self, x):
5+
"""
6+
:type x: int
7+
:rtype: bool
8+
"""
9+
num1_string = str(x) ### For converting integer to string since I want to compare each digit of integer.
10+
length = len(num1_string)
11+
if length == 1: #### This statement checks that integer has one digit, if it does, returns 1 immidaetly.
12+
return True
13+
for i in range(length//2):
14+
if num1_string[i] != num1_string[length-i-1]: #### Checking that number is symmetric, if it is not return 0 directly.
15+
return False
16+
break
17+
elif i == length//2-1: #### Verify that we checked all digits in first half has symmetric and we reached middle point without break. Therefore, return 1.
18+
return True

0 commit comments

Comments
 (0)