This problem supposes that negative numbers are not palindromic. We can divide the cases into odd and even length, or we can combine them together.
Solution:
# T:O(n) S:O(1)
class Solution:
# @param {integer} x
# @return {boolean}
def isPalindrome(self, x):
if x < 0:
return False
x = str(x)
for i in xrange(len(x)/2):
if x[i] != x[len(x) - i - 1]:
return False
return True
Run Time: 260 ms
No comments:
Post a Comment