Leetcode:9. Palindrome Number

这题要求不能使用额外的空间,我也就没做,看了下别人的代码,挺有意义的一道题目,出坏了。
解题思路:从右往左颠倒过来,看看这个值和原来的x值是不是一样,最后还要注意像20这种情况,也是的
public boolean isPalindrome(int x) {
if (x<0 || (x!=0 && x%10==0)) return false;
int rev = 0;
while (x>rev){
rev = rev*10 + x%10;
x = x/10;
}
return (x==rev || x==rev/10);
}
Leetcode:9. Palindrome Number的更多相关文章
- leetcode bug & 9. Palindrome Number
leetcode bug & 9. Palindrome Number bug shit bug "use strict"; /** * * @author xgqfrms ...
- 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字
我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...
- leetcode题解 9. Palindrome Number
9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...
- 【LeetCode】9. Palindrome Number (2 solutions)
Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...
- C# 写 LeetCode easy #9 Palindrome Number
9.Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome when it ...
- leetcode 第九题 Palindrome Number(java)
Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...
- LeetCode(9) - Palindrome Number
题目要求判断一个整数是不是回文数,假设输入是1234321,就返回true,输入的是123421,就返回false.题目要求in-place,思路其实很简单,在LeetCode(7)里面我们刚好做了r ...
- 【一天一道LeetCode】#9. Palindrome Number
一天一道LeetCode系列 (一)题目 Determine whether an integer is a palindrome. Do this without extra space. Some ...
- LeetCode Problem 9:Palindrome Number回文数
描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
随机推荐
- [转]Mysql命令
1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...
- hbase shell-dml(数据管理指令)
hbase shell数据管理篇: append count delete deleteall get get_counter get_splits incr put scan truncate tr ...
- STL 之map解决 Message Flood(原字典树问题)
Message Flood Time ...
- how to close the old Session - if the same username starts a new Session?
Question: want to close the old Session - if the same username starts a new Session Any ideas how i ...
- 本地连接出现"已启用检测该状态的服务"解决方法、方案
1.运行 输出dcomcnfg 2.组件服务-计算机-我的电脑-DCOM配置-netprofm 3.右键属性-安全-启动和激活权限-自定义 4.编辑-添加-输入对象名称来选择-输入“LOCAL SER ...
- 51nod1613
题意:给定n个正面朝上的硬币,每次可以翻转k个硬币,求至少多少次翻转能使之全部反面朝上. 神犇题解 我真的吐槽不能了..这题能做?! 极其复杂的分类讨论..膜拜这位爷.
- Spark- Transformation实战
RDD的算子分为两类,是 Trans formation(Lazy),一类是 Action(触发任务执行RDD不存在真正要计算的数据,而是记录了RDD的转换关系(调用了什么方法,传入什么函数) RDD ...
- Redis安装以及基本操作命令
Redis安装 cd redis-2.6.14make PREFIX=/usr/local/redis install 可能会出现的错误提示>>提示1:make[3]: gcc:命令未找到 ...
- PHP获取当前日期及本周一是几月几号的方法
这篇文章主要介绍了PHP获取当前日期及本周一是几月几号的方法,涉及php时间戳.日期转换与运算相关操作技巧,需要的朋友可以参考下 本文实例讲述了PHP获取当前日期及本周一是几月几号的方法.分享给大家供 ...
- leetcode 50. Pow(x, n)(快速幂)
就是一个二分法快速幂. 但是需要注意的问题是这里是实数,而且n可能为负.int的范围是-2,147,483,648 至 2,147,483,647.如果为-2,147,483,648那么直接n=-n就 ...