LeetCode(34)-Palindrome Number
题目:
Determine whether an integer is a palindrome. Do this without extra space.
思路:
- 求一个整数是不是回文树。负数不是,0是
- 要求不适用额外的内存(变量还是可以的),利用求余,除以10,这样y = y×10+余树,比较y和输入值是否相等,判断是不是回文
-
代码:
public class Solution {
public boolean isPalindrome(int x) {
if(x < 0){
return false;
}
if(x == 0){
return true;
}
if(x > 0){
int finish = x;
//用来存放倒叙相乘的结果
int y = 0;
while(x != 0){
y = y*10 + x%10;
x = x/10;
}
return finish == y ? true:false;
}
return true;
}
}
LeetCode(34)-Palindrome Number的更多相关文章
- Leetcode练习题 Palindrome Number
9. Palindrome Number Question: Determine whether an integer is a palindrome. An integer is a palindr ...
- Leetcode 9. Palindrome Number(水)
9. Palindrome Number Easy Determine whether an integer is a palindrome. An integer is a palindrome w ...
- leetcode 9 Palindrome Number 回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- LeetCode 9. Palindrome Number (回文数字)
Determine whether an integer is a palindrome. Do this without extra space. 题目标签:Math 题目给了我们一个int x, ...
- Leetcode 9. Palindrome Number(判断回文数字)
Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...
- [LeetCode][Python]Palindrome Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/palindr ...
- 蜗牛慢慢爬 LeetCode 9. Palindrome Number [Difficulty: Easy]
题目 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
- [LeetCode] 9.Palindrome Number - Swift
Determine whether an integer is a palindrome. Do this without extra space. 题目意思:判断一个整数是否是回文数 例如:1232 ...
- [LeetCode] 9. Palindrome Number 验证回文数字
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...
随机推荐
- shell 数据流重定向操作符总结
最近看了鸟哥私房菜关于shell数据流重定向的内容,总结一下. 操作符: 1.标准输入(stdin):代码为0,符号:< 或者<< 2.标准输出(stdout):代码为1,符号:&g ...
- Dynamics CRM 开启EmailRouter日志记录
找到mailrouter的安装路径,在service文件夹下找到"Microsoft.Crm.Tools.EmailAgent.xml"这个文件,已管理员方式打开,找到loglev ...
- Linux 64位下一键安装scipy等科学计算环境
Linux 64位下一键安装scipy等科学计算环境 采用scipy.org的各种方法试过了,安装还是失败.找到了一键式安装包Anaconda,基本python要用到的库都齐了,而且还可以选择安装到其 ...
- Nginx创建密码保护目录
nginx 的根目录 为:/home/undoner/nginx-wwwnginx 访问地址 为:http://127.0.0.1本文实现对nginx根目录文件访问的权限控制 (1)nginx指定密码 ...
- (NO.00004)iOS实现打砖块游戏(十一):"一闪一闪亮晶晶,我们都是小星星"
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 现在一个基本的游戏逻辑已经搭建好了,但是感觉还是缺点什么呢? 蠢 ...
- 【一天一道LeetCode】#122. Best Time to Buy and Sell Stock II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Say you ...
- IDEA中运行KafkaWordCount程序
1,从spark的example中找到KafkaWordCount.scala文件复制到idea编辑器中,引入包: 2,编辑configuration, (1)KafkaWordCountPr ...
- Cocos2D:塔防游戏制作之旅(九)
炮塔哲学:敌人,攻击波和路径点 在创建敌人之前,让我们先为它们"铺路".敌人将沿着一系列的路径点前进,这些路径点互相连接,它们被定义为敌人在你创建的世界中移动的路径. 敌人将在第一 ...
- 【翻译】使用Sencha Ext JS 6打造通用应用程序
原文:Using Sencha Ext JS 6 to Build Universal Apps {.aligncenter} 在Sencha和整个Ext JS团队的支持下,我很高兴能跟大家分享一下有 ...
- javascript之DOM编程改变CSS样式(简易验证码显示)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...