Problem 9.Palindrome Number
2015-06-24 20:11
183 查看
Determine whether an integer is a palindrome. Do this without extra space.
leetcode 9.Palindrome Number
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.
};
leetcode 9.Palindrome Number
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.
class Solution { public: bool isPalindrome(int x) { unsigned int y=x; unsigned long long res=0; if(x<=0) y=-x; while(x){ res=res*10+x%10; x=x/10; } if(res==y) return true; else return false; }
};
相关文章推荐
- 【正途】Android R.java文件丢失的问题
- 磁盘空间检查
- XML
- jquery监听回车键自动提交
- Create a Bundle Jar With Ant:使用Ant创建一个包含所有依赖的JAR包
- 解决 Errors running builder 'DeploymentBuilder' on project ' .
- OC7_代理的基本概念
- setContentView( )方法
- 编程之美
- java——获取一个应用程序运行的次数,如果超过5次,给出使用次数已到请注册的提示,并不要再运行程序
- urlurl
- 我的第一个博客
- 07-排序2. Insert or Merge (25)
- 第1章 游戏之乐——让CPU占用率曲线听你指挥
- LeetCode:Same Tree
- android---xml---include用法(导入另一个XML文件到本布局中)
- 由普利姆算法想到一个游戏之后
- nsurl
- Windows live Writer博客园,51CTO,网易博客,新浪博客配置方法
- xml解析与保存