Leetcode 3——Palindrome Number(回文数)
Problem:
Determine whether an integer is a palindrome. Do this without extra space.
简单的回文数,大一肯定有要求写过,不过从基础开始尝试吧。
Solution:
public class Solution {
public boolean isPalindrome(int x) {
int n=1;
int copyx=x;
if(x<0)return false;
if(x<10)return true;
while(x>=10){
x=x/10;
n++;
if(x<10)break;
}
if(n%2==0)
{
while(copyx/(int)Math.pow(10,n-1)==copyx%10)
{
copyx=copyx%(int)Math.pow(10,n-1);
copyx=copyx/10;
// if(x==0)return true;
n=n-2;
if(n==0)return true;
}
}
if(n%2==1)
{
while(copyx/(int)Math.pow(10,n-1)==copyx%10)
{
copyx=copyx%(int)Math.pow(10,n-1);
copyx=copyx/10;
// if(x==0)return true;
n=n-2;
if(n==1)return true;
}
}
return false;
}
}
Leetcode 3——Palindrome Number(回文数)的更多相关文章
- 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 Problem 9:Palindrome Number回文数
描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
- 【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 ...
- Palindrome Number 回文数
判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出. ...
- 【LeetCode】9 Palindrome Number 回文数判定
题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...
- 9. Palindrome Number 回文数的判断
[抄题]: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the sam ...
随机推荐
- lvs简单使用
LB集群实现 硬件 F5 BIG-IP Citrix NetScaler A10 Redware 软件 1 lvs 2 haproxy 3 nginx 4 ats apache traffic ser ...
- Python实现一些常用排序算法
一些常用的排序 #系统内置排序算法#list.sort()#heapq模块 def sys_heap_sort(list): import heapq heap = [] for i in range ...
- win10 更新系统更新补丁后无法启动处理办法
win10无法启动不用怕!WinRE恢复环境轻松修复win10系统 Win10技术预览版发布至今,已经整整过去十天时间.经过这段时间的使用体验,小伙伴们有没有遇到一些问题,导致系统出错甚至无法启动呢? ...
- doT.js模板引擎及基础原理
时至今日,基于后端JavaScript(Node.js)和MVC思想也开始流行起来.模板引擎是数据和页面分离工作中最重要的一环,在各大门户网站均有利用到模板引擎. 模板引擎有很多种,但是原理了解也是非 ...
- halcon c++ 异常处理
现象 Halcon导出的C++程序,try catch不到异常.在Halcon下可以正常Catch到异常. C++代码:try{ tuple_max(hv_Length, &hv_Max ...
- GridView中添加行单击事件.md
[toc] 1.使用说明 1.方法来源 该方法主要参考StackOverflow上面的答案和下面这篇文章 http://www.codeproject.com/Articles/15677/Click ...
- Gedit : 我的开场白 [TPLY]
为什么用Gedit 在学校的高一新生里,好像就只有我使用Gedit 大家都笑我是"用记事本编程的人" 我就想 到考场看看你们笑得出来不 先放一个高配emacs配置 (global- ...
- [.NET Core] 简单读取 json 配置文件
简单读取 json 配置文件 背景 目前发现网上的 .NET Core 读取配置文件有点麻烦,自己想搞个简单点的. .NET Core 已经不使用之前的诸如 app.config 和 web.conf ...
- 使用mysql将备份的sql文件导入到数据库
一.背景 承接上一篇文章<如何使用mysqldump备份数据库>,数据库备份后将用于恢复或者在多个测试环境上迁移.下面描述如何通过批处理文件实现数据加载恢复. 二.环境准备 跟上一篇一样, ...
- java 多态 ---父类调用子类方法
package test1;//多态的体现import javax.print.attribute.standard.RequestingUserName;import java.util.Scann ...