【LeetCode】LeetCode——第9题:Palindrome Number
2016-04-19 10:31
411 查看
9. Palindrome Number
My SubmissionsQuestion
Editorial Solution
Total Accepted: 118962 Total
Submissions: 377213 Difficulty: Easy
Determine whether an integer is a palindrome. Do this without extra space.
click to show spoilers.
Some hints:
Could negative integers be palindromes? (ie, -1)
If you are thinking of converting the integer to string, note the restriction of using extra space.
You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
There is a more generic way of solving this problem.
Subscribe to see which companies asked this question
Show Tags
Show Similar Problems
题目的大概意思是:判断一个整型(int)数是否是回文数。
这道题难度等级:简单
解题思路是:判断反转后的数是否与原来的数相等。
需要注意的是:翻转后的数可能会有溢出情况;另外,负数不是回文数。
代码如下:
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0){return false;}
int tmp = x;
long y = 0;
while(tmp){
y = y * 10 + tmp % 10;
tmp /= 10;
}
return x == y;
}
};提交代码后,顺利AC掉,Runtime: 76
ms。
相关文章推荐
- Howto - Install MT7610U on CentOS 6.6
- c++ container
- 104. Maximum Depth of Binary Tree
- 常见锁的区别及适用场景
- 你真的会用Fragment了么?-Fragment解析
- windows mongodb 安装
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- 页面向下滑动实现div显示和隐藏
- android 禁用点击事件的三个属性
- iOS线程通信
- Mat类详解(三)
- 273. Integer to English Words
- 对我有价值的文章记录
- Java中的Constants类
- update_TypeError
- 英译中批量翻译
- linux 红帽6.5修改root密码
- ionic基础概念
- Mybatis学习记录(五)--整合spring开发Dao
- gdb