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(回文数)的更多相关文章

  1. leetcode 9 Palindrome Number 回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  2. [LeetCode]9. Palindrome Number回文数

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...

  3. 【LeetCode】Palindrome Number(回文数)

    这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...

  4. LeetCode Problem 9:Palindrome Number回文数

    描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...

  5. 【LeetCode】9. Palindrome Number 回文数

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...

  6. [LeetCode] Prime Palindrome 质数回文数

    Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...

  7. Palindrome Number 回文数

    判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出.     ...

  8. 【LeetCode】9 Palindrome Number 回文数判定

    题目: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could neg ...

  9. 9. Palindrome Number 回文数的判断

    [抄题]: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the sam ...

随机推荐

  1. Python实现常用的数据结构

    Python中的数据结构   #巧用Python列表特性实现特定数据结构 #栈实现stack = []stack.push(x)stack.pop()stack[-1] #队列实现from colle ...

  2. emWin 2天速成实例教程000_如何快速入门ucGUI/emWin

    备注:(1)打开工程目录下的"Exe\GUISimulationDebug.exe"即可看到效果.(2)看完教程000-005就基本会用emWin做项目,其他章节可以需要时再参考. ...

  3. 用yeoman搭建react画廊项目笔记

    1.安装yeoman   npm install yo -g yo --version //检测 yeoman版本,成功显示版本号,则安装成功 2.到yeoman官网 http://yeoman.io ...

  4. Codeforces Round #466 (Div. 2) 题解

    人生中第三次\(CF\)... 考试中切了\(A\)~\(E\) \(F\)题会做没时间写 题解 A:Points on the line 题意 给定一个数列,删最小的数,使最大差不大于一个定值 So ...

  5. [BZOJ4034] [HAOI2015] T2 (树链剖分)

    Description 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操作 2 :把某个节点 x 为根的子树中所 ...

  6. Zabbix 监控 Docker容器

    我们可以通过Python提供的模块docker来取各个docker容器的监控参数.参考文档:http://docker-py.readthedocs.io/en/stable/containers.h ...

  7. Oracle数据库中in()参数超过一千报错代码报错

    转载请注明出处:http://www.cnblogs.com/xunzhaorendaxia/p/8570604.html 解决方案将select * from tablename where fie ...

  8. 读取MySQL存储二进制的语音、图片(Blob类型)

    /**   * 下载语音   * Remarks:   * @throws Exception   */ public void downloadYuyin() throws Exception { ...

  9. 同一台电脑同时装Oracle客户端和服务端

    1.如果之前安装过Oracle,Win+R输入Services.msc,关掉以Oracle开头的服务(卸载Oracle服务端和客户端步骤一样,见另外一篇帖子) 2.Win+R输入regedit打开注册 ...

  10. webapi下的web请求

    先看webapi提供的服务: [HttpPost] public ResultBaseModel SiteList(SiteModel param) { ResultBaseModel resultM ...