【leetcode】 9. palindrome number
2015-07-13 09:53
381 查看
@requires_authorization @author johnsondu @create_time 2015.7.13 9:48 @url [palindrome-number](https://leetcode.com/problems/palindrome-number/) /************************ * 分离出最左边和最右边的数 * 然后依次对比即可 ***********************/ class Solution { public: bool isPalindrome(int x) { if(x < 0) return false; if(x < 10) return true; int base = 1; while(x / base >=10) base *= 10; while(x) { int ld = x / base; int rd = x % 10; if(ld != rd) return false; x -= ld * base; x /= 10; base /= 100; } return true; } };
相关文章推荐
- ie盒子模型和高级浏览器的区别
- 三维数组 计算深度平均值
- GC overhead limit exceeded
- Java调试
- 如何在OpenWRT的非交换网卡/单口网卡(OpenWRT x86)下配置802.1Q VLAN
- Java 中的关键字 synchronized详解
- Apache配置错误日志
- 12门徒数到3被挑出找出最后剩下的叛徒
- 统计字符串中每个字符的个数
- 引用计数型智能指针
- 颐和园终于上CSDN头条了
- 基于Web和二维码的文件传输服务
- 使用QUnit对JS进行单元测试
- 浅谈javascript原型链与继承
- bzoj1415: [Noi2005]聪聪和可可 记忆化搜索
- vim 的分屏与多标签应用
- jsoup Cookbook(中文版)-Jsoup解析HTML
- java与c#的区别(一)
- 查找字符串中单词最长的
- 深入理解Spring Redis的使用 (四)、RedisTemplate执行Redis脚本