LeetCode | Palindrome Number
2015-06-09 01:42
295 查看
Palindrome Number
Total Accepted: 59751 TotalSubmissions: 200784My Submissions
Question
Solution
Determine whether an integer is a palindrome. Do this without extra space.
click to show spoilers.
Show Tags
Math
Have you met this question in a real interview?
Yes
No
Discuss
思路:就是那样QAQ,很普通的回文判断,WA点:负数不是回文数。
实现代码:
<span style="font-size:12px;">class Solution { public: bool isPalindrome(int x) { if(x<0) return false; int cnt=0; int a[100]; memset(a,0,sizeof(a)); while(x) { int c=x%10; a[cnt++]=c; x/=10; } int i,j; for(i=0,j=cnt-1;i<j;i++,j--) { if(a[i]!=a[j]) return false; } return true; } };</span>
相关文章推荐
- linux fdisk 下磁盘查看命令分享很简单
- Codeforces Round #306 (Div. 2) (ABCE题解)
- OpenLayers学习笔记5——使用jQuery UI实现查询并标注(UI篇)
- Java NIO使用及原理分析 (四)
- [Swust OJ 1094]--中位数(巧用set,堆排序)
- shutdown reboot init 重启命令 关机命令 简单介绍
- HDU 5266 pog loves szh III ( LCA + SegTree||RMQ )
- qt大全(连接)
- EXCEL文件行交替背景色设置
- HDU 5265 pog loves szh II
- win8中如何设定editplus为txt默认打开程序
- 循环顺序队列2——使用标示位判断队满或空
- EXCEL内的字符比较公式
- 2015区域赛起航
- 菜鸟学Android笔记(二十六):Response数据输出
- APP Launchimage软件启动图片
- 黑马程序员_多线程间通信
- UVA 10635 Prince and Princess 最长公共子序列(nlongn)
- Rectangle Area
- mount 挂接命令及技巧光盘镜像文件、移动硬盘及U盘 简单说明