You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#### 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.
0 commit comments