LeetCode 9 Palindrome Number(回文数字判断)
package leetcode; /***
*
* @author pengfei_zheng
* 判断回文数字
*/
public class Solution09 {
public boolean isPalindrome(int x) {
if(x < 0) //小于0返回false
return false;
int len = 1;
while(x/len >= 10)
len *=10;//求出x的位数对应的pow(10,n)
while(x>0){
int left = x / len;//取x的最高位
int right = x % 10;//取x的最低位 if(left != right)//有不等则返回false
return false;
else {
x = (x % len) / 10;//修改x的值 求模运算去掉最高位 除法运算去掉最低位
len /= 100;//修改x的位数对应的pow(10,n)
}
}
return true;
}
};
LeetCode 9 Palindrome Number(回文数字判断)的更多相关文章
- 【LeetCode每天一题】Palindrome Number( 回文数字)
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...
- 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. An integer is a palindrome when it reads the same back ...
- 【LeetCode】Palindrome Number(回文数)
这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...
- Leetcode 3——Palindrome Number(回文数)
Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...
- 【LeetCode】9. Palindrome Number 回文数
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...
- [LeetCode] Prime Palindrome 质数回文数
Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode Valid Palindrome 有效回文(字符串)
class Solution { public: bool isPalindrome(string s) { if(s=="") return true; ) return tru ...
随机推荐
- SpringBoot和SpringCloud配置
1.基本配置 #项目名称(访问路径) server.context-path=/manager #端口 server.port=8764 #session过期时间 server.sessionTime ...
- CocoaPods:说点关于它的
CocoaPods安装和使用教程 安装及使用方法,这里有现成的,很细致,不再赘述(发音:zhuìshù,敲半天ao'shu,找不到这个词 =.=) 记录一下遇到的问题 1.CocoaPods 版本 ...
- 边框颜色为 tintColor 的 UIButton
创建一个 UIButton 的子类,重写其方法: - (void)drawRect:(CGRect)rect { [[self layer] setCornerRadius:CORNER_RADIUS ...
- 查看cp进度,使用watch
watch -n 1 -d du -sh dir 每隔1s查看当前目录所占空间大小
- web.py开发
web.py需要使用python2.X,所以安装python版本2.7.9 web.py 是一个轻量级Python web框架,它简单而且功能强大 web.py安装 安装python (1)使用pip ...
- Java如何取得当前程序部署的服务器的IP
1.问题:之前使用InetAddress.getLocalHost().getHostAddress()时,在开发机测试可以得到192.168.0.18这样的IP.但部署到linux服务器以后, 这个 ...
- opengl库区分:glut、freeglut、glfw、glew、gl3w、glad
//oepngl库 opengl原生库 gl* 随opengl一起发布 opengl实用库 glu* 随opengl一起发布 opengl实用工具库glut glut* 需要下载配置安装(太老了!) ...
- OpenGL中的光照技术(翻译)
Lighting:https://www.evl.uic.edu/julian/cs488/2005-11-03/index.html 光照 OpenGL中的光照(Linghting)是很重要的,为什 ...
- Ubuntu18.10安装网易云音乐(图文并茂!)
听音乐,怎么少得了网易云音乐,下面我们在Ubuntu18.10上来安装下: 首先进入网易云音乐的下载页:https://music.163.com/#/download,选择下载Ubuntu版本: 我 ...
- mysql 日志操作
https://www.cnblogs.com/dreamworlds/p/5478293.html http://www.jb51.net/article/76886.htm