LeetCode :: Palindrome
来源:互联网 发布:软件定义存储产品 编辑:程序博客网 时间:2024/05/02 04:48
今天真是lucky,随机到的题目都比较简单。
这里判断回文数字。Determine whether an integer is a palindrome. Do this without extra space.
题目也是很简短,唯一值得注意的是,负数全部不是回文数字,一开始我没考虑到负数,所以没AC。
这里用 long long 来存在取反的数字,来避免越界问题。
class Solution {public: bool isPalindrome(int x) { bool isP = false; if (x < 0) return isP; long long Reverse = 0; long long input = x; while (x){ Reverse = Reverse * 10 + x % 10; x /= 10; } if (Reverse == input) isP = true; return isP; }};PS: 我试着把 long long 改为 int 也是没有问题的, 好像没设置这个越界case。
0 0
- LeetCode :: Palindrome
- LeetCode: Palindrome Number
- LeetCode Palindrome Number
- [Leetcode] Palindrome Number
- LeetCode: Palindrome Number
- [Leetcode] Valid Palindrome
- Leetcode: Valid Palindrome
- leetcode 55: Valid Palindrome
- [LeetCode] Valid Palindrome
- [LeetCode] Palindrome Number
- LeetCode: Palindrome Partitioning
- LeetCode : Palindrome Partitioning II
- leetcode 117: Palindrome Number
- Leetcode : Palindrome Number
- [leetcode] Palindrome Partitioning II
- leetcode 122: Palindrome Partitioning
- leetcode:Palindrome Partitioning II
- leetcode:Palindrome Partitioning
- AngularJS学习地址
- itv留言板模块
- solr部署
- windows下IIS让flv视频网站进度条随意拖放[C#]
- 一步步学习SPD2010--第二章节--处理SP网站(6)---- 探索SP网站
- LeetCode :: Palindrome
- Oracle用户口令
- linux deepin 2013 使用svn提示**gnome keyring **
- java.lang.NoClassDefFoundError问题的解决办法
- 随着帝企鹅这一系列的组合拳,腾讯将在移动时代以微信为杀伤性核武器
- 如何将App程序发布到苹果App Store
- ThinkPHP 项目分组URL生成与URL访问
- Linux C一站式学习习题答案11.6.2求平方根
- Struts2与freemarker自定义标签