Source of the topic:
https://leetcode.com/problems/palindrome-number/
Test Instructions Analysis:
This question is to determine whether an int is a palindrome number, requiring that no additional space can be requested.
Topic Ideas:
This is also a simple topic, because no additional space can be applied, so int cannot be converted to string to handle. Based on the definition of palindrome number, we can consider flipping an int over, and when flipping, be careful not to exceed the maximum value of 32-bit int.
Code (Python):
1 classsolution (object):2 defIspalindrome (self, x):3 """4 : Type X:int5 : Rtype:bool6 """7 ifX <0:8 returnFalse9b =xTenAns =0 One whileX >0: AAns = ans*10 + x%10 - ifX > 2147483647: - returnFalse theX//= 10 - ifAns = =B: - returnTrue - returnFalse
View Code
Reprint Please specify source: http://www.cnblogs.com/chruny/p/4801704.html
[Leetcode] (python): 009-palindrome number