9. Palindrome Number

题目:

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.

其实就是判断一个数字是不是回文数字。

一开始的思路是找到开始的数字和最后的数字进行比对,发现自己有点天真,哈哈哈,又不是字符串啦,不好比较。

正确的思路就是求出它的相反的那个数,然后判断他们两是不是相等的。

负数的情况感觉应该特判一下都不是回文,没有特判也过了,下面是代码:

 class Solution {
public:
bool isPalindrome(int x) {
int reverse=;
int temp=x;
while(temp>)
{
reverse=reverse*+temp%;
temp=temp/;
}
if(x==reverse)
return true;
else
return false;
}
};

leetcode题解 9. Palindrome Number的更多相关文章

  1. [LeetCode 题解]:Palindrome Number

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Determine ...

  2. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...

  3. leetcode bug & 9. Palindrome Number

    leetcode bug & 9. Palindrome Number bug shit bug "use strict"; /** * * @author xgqfrms ...

  4. leetcode 第九题 Palindrome Number(java)

    Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...

  5. 【LeetCode】9. Palindrome Number (2 solutions)

    Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...

  6. C# 写 LeetCode easy #9 Palindrome Number

    9.Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome when it ...

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

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

  8. LeetCode(9) - Palindrome Number

    题目要求判断一个整数是不是回文数,假设输入是1234321,就返回true,输入的是123421,就返回false.题目要求in-place,思路其实很简单,在LeetCode(7)里面我们刚好做了r ...

  9. 【一天一道LeetCode】#9. Palindrome Number

    一天一道LeetCode系列 (一)题目 Determine whether an integer is a palindrome. Do this without extra space. Some ...

随机推荐

  1. iframe之间的postMessage传参

    1.传参 function IframeClose() { var obj = {method: "iframeClose"}; window.parent.postMessage ...

  2. css实现垂直水平居中的方法(个数不限)?

    方法一:使用绝对定位 大家都知道margin:0 auto;能够实现水平居中,但却不知道margin:0 auto;也是可以实现垂直居中的: 给居中元素添加如下样式: .Absolute-Center ...

  3. centos 7 安装二进制mysql 详细步骤

    1 下载地址:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz 复制这个链接在 ...

  4. excel 批量上传图片

    1.在excel中  输入公式  ="<table><img src=""D:\素材\"&A2&".jpeg&quo ...

  5. 菜鸟脱壳之脱壳的基础知识(六)——手动查找IAT和修复Dump的程序

    前面讲了如何寻找OEP和脱壳,有的时候,Dump出来的时候不能正常运行,是因为还有一个输入表没有进行处理,一些加密壳会在IAT加密上面大做文章,用HOOK - API的外壳地址来代替真是的IAT的地址 ...

  6. oracle存储过程出现ORA-01403: 未找到数据 问题解决方法

    这段时间在做一个业务,需要用到存储过程处理业务逻辑,但是出现一个ORA-01403: 未找到数据 问题, 那么这个应该如何解决这个问题 declare mixType integer; begin - ...

  7. hdu1256

    画横线总是一个字符粗,竖线随着总高度每增长6而增加1个字符宽.当总高度从5增加到6时,其竖线宽度从1增长到2.下圈高度不小于上圈高度,但应尽量接近上圈高度,且下圈的内径呈正方形.每画一个"8 ...

  8. Ubuntu开机启动roscore服务的设置

    1.在/etc/init.d中添加启停脚本ros_daemon.bash: #!/bin/bash ### BEGIN INIT INFO # Provides: ros_daemon.bash # ...

  9. Winsock API编程介绍

    相信很多人都对网络编程感兴趣,下面我们就来介绍,在网络编程中应用最广泛的编程接口Winsock API. 使用Winsock API的编程,应该了解一些TCP/IP的基础知识.虽然你可以直接使用Win ...

  10. Github 搭建 Hexo 纯静态化个人博客平台

    以前一直想搭建一个属于自己的博客平台,有余种种原因一直未能实现,最近闲来无事,参照网上的教程,搭建了属于自己的博客.自己的博客网站,样式自由,不需要受限于各大平台. 本篇为从零开始的基础篇,本篇所包含 ...