题目:

  1. Determine whether an integer is a palindrome. Do this without extra space.

思路:

  • 求一个整数是不是回文树。负数不是,0是
  • 要求不适用额外的内存(变量还是可以的),利用求余,除以10,这样y = y×10+余树,比较y和输入值是否相等,判断是不是回文
  • -

代码:

  1. public class Solution {
  2. public boolean isPalindrome(int x) {
  3. if(x < 0){
  4. return false;
  5. }
  6. if(x == 0){
  7. return true;
  8. }
  9. if(x > 0){
  10. int finish = x;
  11. //用来存放倒叙相乘的结果
  12. int y = 0;
  13. while(x != 0){
  14. y = y*10 + x%10;
  15. x = x/10;
  16. }
  17. return finish == y ? true:false;
  18. }
  19. return true;
  20. }
  21. }

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. JDBC编程-优化程序(六)

    首先完成DTO类的编写 DTO类是data tranfer object也就是数据传输类,DTO主要用于数据的传输操作,其中包含属性值,以及构造方法和getter ,setter方法等,不会包含业务逻 ...

  2. GDAL不支持创建PCIDSK的面状矢量格式

    最近在使用GDAL创建PCIDSK格式的矢量数据,发现创建点和线的矢量数据都没问题,创建面状的只有属性表没有图形.在GDAL官网说明也写的是支持的,地址为:http://www.gdal.org/fr ...

  3. ExpandableListView简单应用及listview模拟ExpandableListView

    首先我们还是来看一些案例,还是拿搜狐新闻客户端,因为我天天上下班没事爱看这个东东,上班又没时间看新闻,上下班路途之余浏览下新闻打发时间嘛.           看这个效果挺棒吧,其实实现起来也不难,我 ...

  4. JQuery实战--可以编辑的表格

    廊坊下雪了,15年的第二场雪,比14的来的稍晚一些,停靠在11教门前的自行车,成了廊坊师范学院最美丽的风景线.还记得以前学习css的时候,就曾经接触过如何编写设计一些表格和表单的样式,例如如何设计表格 ...

  5. Java --Annotation学习心得体会及笔记

    相对于注释这种给程序员看的信息: 注解,就是给程序看的解释性的语言,其作用就相当于配置文件的存在.其存在的意义在于以下几点: 优点: 方便的使程序员看到相关项的关联位置及关联方式等信息. 缺点: 由于 ...

  6. 03 RadioButton 单选按钮

    >概念:从多个互斥选项中选择一个  如果是选项全部展开  RadioButton  不是展开的Spinner(下拉列表)     >属性: android:checked="tr ...

  7. 【翻译】Ext JS最新技巧——2015-10-21

    原文:Top Support Tips Kevin Cassidy:全宽度的字段错误信息 有考虑过让验证信息显示在表单字段的下面(msgTarget:'under'),但最后发现验证信息被压缩显示了吗 ...

  8. awk 详解+实例

    1. awk简介 awk是一种编程语言,用于在linux/unix下对文本和数据进行处理.数据可以来自标准输入.一个或多个文件,或其它命令的输出.它支持用户自定义函数和动态正则表达式等先进功能,是li ...

  9. linux shell编程语句if、case.

    shell学习笔记--if,case shell的控制流结构主要有if语句.for语句.case语句.while语句.until语句这五种,在shell中这些语句的用法有点类似C语言,很容易学会,但也 ...

  10. 【一天一道LeetCode】#76. Minimum Window Substring

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...