首页 > 其他 > 详细

[LeetCode] Palindrome Number

时间:2015-08-15 16:14:46      阅读:225      评论:0      收藏:0      [点我收藏+]

The most obvious idea is to maintain two divisors to get the most and least significant digits and compare them. Well, there are much more clever ideas, like this one, whose code is rewritten below. Play with it :-)

 1 class Solution {
 2 public:
 3     bool isPalindrome(int x) {
 4         if (x < 0 || (x && !(x % 10))) return false;
 5         int s = 0;
 6         while (x > s) {
 7             s = s * 10 + x % 10;
 8             x /= 10;
 9         }
10         return x == s || x == s / 10;
11     }
12 };

 

[LeetCode] Palindrome Number

原文:http://www.cnblogs.com/jcliBlogger/p/4732539.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!