题目:

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的更多相关文章

  1. Leetcode练习题 Palindrome Number

    9. Palindrome Number Question: Determine whether an integer is a palindrome. An integer is a palindr ...

  2. Leetcode 9. Palindrome Number(水)

    9. Palindrome Number Easy Determine whether an integer is a palindrome. An integer is a palindrome w ...

  3. leetcode 9 Palindrome Number 回文数

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

  4. LeetCode 9. Palindrome Number (回文数字)

    Determine whether an integer is a palindrome. Do this without extra space. 题目标签:Math 题目给了我们一个int x, ...

  5. Leetcode 9. Palindrome Number(判断回文数字)

    Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...

  6. [LeetCode][Python]Palindrome Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/palindr ...

  7. 蜗牛慢慢爬 LeetCode 9. Palindrome Number [Difficulty: Easy]

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

  8. [LeetCode] 9.Palindrome Number - Swift

    Determine whether an integer is a palindrome. Do this without extra space. 题目意思:判断一个整数是否是回文数 例如:1232 ...

  9. [LeetCode] 9. Palindrome Number 验证回文数字

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

随机推荐

  1. python地理数据处理库geopy

    http://blog.csdn.net/pipisorry/article/details/52205266 python地理位置处理 python地理编码地址以及用来处理经纬度的库 GeoDjan ...

  2. UNIX环境高级编程——标准IO-实现查看所有用户

    #include <string.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h&g ...

  3. 如何查看Android设备上的分区信息

    Android设备上,一般都会存在一块eMMC存储芯片来存放系统和用户数据,甚至部分的引导程序. 一般设备出厂时,各个厂商都会将这块存储芯片分成很多的分区,每个分区内存放不同的内容.具体分区的布局每个 ...

  4. android开发之broadcast学习笔记

    android中的广播用的太多了,今天稍微总结一下. 按注册方式分为两种: 1.静态注册广播: 静态注册广播就是在androidManifest.xml文件中注册广播,假设我们要实现这样一个效果,在一 ...

  5. Android简易实战教程--第四话《最简单的短信发送器》

    首先配置一个布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

  6. web中间件切换(was切tomcat)

    一.数据源迁移: ①数据源配置在web容器还是在项目本身? 根据开发与生产分离原则选择配置到web容器,以免开发泄露数据库密码. ②数据库密码加密 原先was的数据源直接在console控制,密码是密 ...

  7. DB2数据库代码页和实例代码页的区别(解决DB2乱码问题)

    DB2CODEPAGE:     DB2 实例级别的代码页设置,它会影响DB2相关应用程序对代码页转换时做出代码页判定.     可以通过 db2set DB2CODEPAEG= 命令将 DB2COD ...

  8. Arquillian Exception:java.lang.NoClassDefFoundError

    Issue: When you deploy and run Arquillian testcase, you may encountered java.lang.NoClassDefFoundErr ...

  9. Android5.1设备无法识别exFAT文件系统的64G TF卡问题

    64G TF卡刚买回来的时候默认exFAT文件系统,在电脑端(XP和WIN7)可以识别,但在我们Android5.1S设备无法识别,采用guiformat工具格式化为FAT32文件系统后才可以正常识别 ...

  10. c# 单元测试工程如何取得当前项目路径

    前言: C#工程项目中有些配置文件,数据文件等不是C#工程文件,但是程序中需要访问,如果写成绝对路径不利于程序的迁移,所以必须写成相对路径.取得相对路径的方法很多,网上的例子也很多,基本上是七种吧,这 ...