题目

      这道题是迄今为止最快通过的一道题,改了两次就过了,runtime一般(中等偏下,这点不太满意)。Palindrome就是判断一个整数是否对称。

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

click to show spoilers.

Some hints:

Could negative integers be palindromes? (ie, -1)

If you are thinking of converting the integer to string, note the restriction of using extra space.

You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?

There is a more generic way of solving this problem.

代码

public class Solution {public boolean isPalindrome(int x) {if(x<0){return false;}else{if(x==0){return true;}else{int temp=0;int temp_x=0;temp=x;while(temp/10!=0 || (temp<=9 && temp>0)){temp_x=temp_x*10;temp_x+=temp%10;temp=temp/10;}//  System.out.print(""+temp_x);if(x==temp_x){return true;}else{return false;}}}}}
代码下载:https://github.com/jimenbian/GarvinLeetCode

/********************************

* 本文来自博客  “李博Garvin“

* 转载请标明出处:http://blog.csdn.net/buptgshengod

******************************************/

【LeetCode从零单排】No.9 Palindrome Number相关推荐

  1. 【LeetCode从零单排】No 191.Number of 1 Bits(考察位运算)

    题目 Write a function that takes an unsigned integer and returns the number of '1' bits it has (also k ...

  2. 【LeetCode从零单排】No198.House Robber No91.Decode Ways139 word break(动态规划典型应用)

    1.题目 一道典型的Dynamic Programming的题目. You are a professional robber planning to rob houses along a stree ...

  3. 【LeetCode从零单排】No129 Sum Root to Leaf Numbers

    题目 Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a num ...

  4. 【LeetCode从零单排】No104 Maximum Depth of Binary Tree

    题目 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the l ...

  5. 【LeetCode从零单排】No88.Merge Sorted Array

    题目 Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume ...

  6. 【LeetCode从零单排】No70.ClimbingStairs

    题目 爬楼梯问题,这是一道很有趣的问题.首先看题目: You are climbing a stair case. It takes n steps to reach to the top. Each ...

  7. 【LeetCode从零单排】No26.Remove Duplicates from Sorted Array

    题目      题目要求:去除sort int数组中的重复项. Given a sorted array, remove the duplicates in place such that each ...

  8. 【LeetCode从零单排】No.7 Reverse Integer

    前话       今天开始励志刷一下leetcode上面的题目(还好这个网站没被TG和谐).从easy的开始,数一下差不多有40道,争取两个月搞定. 题目        没想到做的第一道题目,虽然看似 ...

  9. 【LeetCode从零单排】No.135Candy(双向动态规划)

    1.题目 There are N children standing in a line. Each child is assigned a rating value. You are giving ...

最新文章

  1. 深入聊一聊 Spring AOP 实现机制
  2. lua 多条件_【LUA】只需花费你半天时间
  3. Zabbix监控 之 OID动态索引
  4. 内存不能“read”
  5. (241)IC验证工程师技能树
  6. c语言 mysql 查询数字_c语言mysql查询数据库
  7. 回归分析什么时候取对数_技术派|SPSS数据分析心得小结及心得分享!必备收藏...
  8. java 批次号生成_批次号生成
  9. docker 镜像源_前端 Docker 镜像体积优化
  10. 做scratch游戏心得1
  11. JavaScript基础复习下(51st)
  12. < 知识拓展:CSS 中常用的计量单位有哪些? >
  13. python 金融发欺诈_python金融反欺诈-项目实战
  14. 计算机网络-数据交换技术
  15. 魔兽世界网站服务器搭建,网游服务器搭建方案图解(以魔兽世界为例)(示例代码)...
  16. 【云原生】裸金属架构之服务器安装VMWare ESXI虚拟化平台详细流程
  17. python 调用Multipart类型接口上传文件和下载文件
  18. jdk1.8的下载与安装教程
  19. win10彻底永久关闭自动更新的方法【已验证有效】
  20. 推荐中的ctr校准方式

热门文章

  1. Linux 内核抓包功能实现基础(三) 抓包服务器的实现
  2. matlab rbf函数_基于径向基函数(RBF)的无网格伪谱法与程序实现(2)——微分矩阵...
  3. mysql索引查询 with_查找mysql中的低效索引
  4. dubbo service注解用法_Dubbo---开源分布式服务框架(一)
  5. phpmailer 私密抄送_使用 phpmailer 发送邮件,支持抄送、密送和发送附件
  6. 使用geopandas 制作中国疫情地图
  7. linux gz bz,linux把文件压缩命令 tar gz bz bz2
  8. ept技术_EPT技术在压载水处理中的运用
  9. limit mongodb 聚合_MongoDB 聚合操作(转)
  10. C语言中7除以14的答案,2015年计算机二级《C语言》精选练习题及答案(14)