The article directory is as follows
(1) Your own ideas
(2) your own code
(3) Other people's ideas
(4) Someone else's code
(5) Compare your shortcomings
(1) Your own ideas
Also met palindrome number, but this time is a lot simpler, because this time just to determine whether a number x is a palindrome number, then only need to reverse an integer, and then save as a new number R, and finally compare the X and r are equal. During the period involved in the remainder, the division operation must have read the code will understand, not many, directly paste code
(2) your own code
classSolution { Public: BOOLIspalindrome (intx) {intTMPX =x; intTMP =0; while(tmpx!=0) {tmp= tmp*Ten+ (tmpx%Ten); TMPX= tmpx/Ten; } return(tmp==x); }};
(3) Other people's ideas
Each time the highest and lowest digits of the integer x are compared, and then the X is disassembled, the highest and lowest bits of x are removed, and then the comparison is continued, and if one is not satisfied, then it is not a palindrome number, otherwise it will be returned to the number of palindrome until the comparison is over.
(4) Someone else's code
classSolution { Public: BOOLIspalindrome (intx) {if(X <0)return false; intD =1;//Divisor while(x/d >=Ten) d *=Ten; while(X >0) { intQ = x/d;//Quotient intr = x%Ten;//remainder if(q! = r)return false; X= x% d/Ten; D/= -; } return true; }};
(5) Compare your shortcomings
I constructed another number r based on the number x, where r is in the opposite order of X. Other people's thoughts only operate on X, and the beginning of a comparison number is equal to the number at the end.
One of my methods has a fatal disadvantage, that is, when the integer is particularly large (beyond the scope of int), in the process of constructing r is prone to error, but other people's methods do not have this problem, so again encountered this problem, try to operate on the same number, so as to avoid the problem of numerical range!
9. Palindrome number