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 ...
随机推荐
- iOS: Sorted Array with Compare
Question(提问): What I want to do seems pretty simple, but I can't find any answers on the web. I have ...
- Xcode 文档注释
首先要下载一个服务:[下载地址]这是一个老外写的工作流,解压缩,然后双击,安装一下, 选择xcode —> services —> services perference 安装完就会在右边 ...
- YFCMF 问题
1.菜单不见了,yf.php (main 改为0 ) function tagMenu $parseStr .='echo get_menu("main","'.$to ...
- 使用DataSource绑定一维数组时,DataTextField只需绑定空字符串
方法定义: public static void InitDropDownList(DropDownList ddl, bool isAddTopItem, DropDownList ddlSub, ...
- SpringMVC工作原理详解
先来看一下什么是 MVC 模式 MVC 是一种设计模式. MVC 的原理图如下: SpringMVC 简单介绍 SpringMVC 框架是以请求为驱动,围绕 Servlet 设计,将请求发给控制器,然 ...
- snmp简单使用
preface snmp 不多说 环境介绍 1.使用CentOs7的系统,内核版本为3.10.0-123.el7.x86_64 2.ip地址为192.168.56.12 安装snmp 1.yum安装: ...
- BarTender复合条形码中的分隔符模式详解
在BarTender 10.1中,支持使用BarTender分隔符模式的复合条形码符号体系包括GS1 Composite和GS1 DataBar (RSS).本文小编给大家详细讲解BarTender分 ...
- C#常用数据加密类
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Sec ...
- re.match re.search re.findall区别
re正则表达式里面,常用的三种方法的区别. re.macth和search匹配得到的是match对象,findall得到的是一个列表. match从字符串开头开始匹配,search返回与正则表达式匹配 ...
- [Scikit-learn] 1.1 Generalized Linear Models - Lasso Regression
Ref: http://blog.csdn.net/daunxx/article/details/51596877 Ref: https://www.youtube.com/watch?v=ipb2M ...