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

class Solution {
public:
bool isPalindrome(int x) {
if(x < ) return false; //别忘了负数的情况
if(x == ) return true; int tmp = x/;
int pHead = ;
int leftDigit, rightDigit, base;
while(tmp){
pHead*=;
tmp /= ;
} while(pHead >= ){
leftDigit = x/pHead;
rightDigit = x%;
if(leftDigit != rightDigit) return false;
x %= pHead;
x /= ;
pHead /= ;
}
return true;
}
};

9.Palindrome Number (INT)的更多相关文章

  1. 65. Reverse Integer && Palindrome Number

    Reverse Integer Reverse digits of an integer. Example1: x =  123, return  321 Example2: x = -123, re ...

  2. 9. Palindrome Number

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

  3. No.009 Palindrome Number

    9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...

  4. 【LeetCode】9 & 234 & 206 - Palindrome Number & Palindrome Linked List & Reverse Linked List

    9 - Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Som ...

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

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

  6. leetcode 第九题 Palindrome Number(java)

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

  7. HDU 5062 Beautiful Palindrome Number(数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...

  8. Reverse Integer - Palindrome Number - 简单模拟

    第一个题目是将整数进行反转,这个题实现反转并不难,主要关键点在于如何进行溢出判断.溢出判断再上一篇字符串转整数中已有介绍,本题采用其中的第三种方法,将数字转为字符串,使用字符串比较大小的方法进行比较. ...

  9. leetcode题解 9. Palindrome Number

    9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...

随机推荐

  1. ubuntu:在ubuntu上安装vmware12

    在ubuntu上安装vmware12 下载vmware12 https://pan.baidu.com/s/1i5BQEmL  官方的 密匙    5A02H-AU243-TZJ49-GTC7K-3C ...

  2. 深入了解 Session 与 Cookie

    Java —— 深入了解 Session 与 Cookie Java web   了解Cookie和Session   定义 1.很通俗的来讲,Cookie就是浏览器的缓存,就是用户访问网站时保存在浏 ...

  3. nginx: [emerg] "fastcgi_pass" directive is duplicate in /etc/nginx/sites-enabled/default:57

    /************************************************************************************************ * ...

  4. JavaWeb入门环境搭建

    一.安装配置Tomcat 1.下载 2.配置环境变量 配置JAVA_HOME环境变量,路径为JDK的根目录 3.测试Tomcat 打开浏览器,在地址栏输入http://localhost:8080可以 ...

  5. cratedb joins 原理(官方文档)

      JOINs are essential operations in relational databases. They create a link between rows based on c ...

  6. 【转】嵌入式Linux文件系统启动脚本及分析

    原文网址:http://www.linuxidc.com/Linux/2011-03/33728.htm 在内核初始化完成后,嵌入式linux 文件系统的启动过程主要包含以下几个步骤: 1. 执行/s ...

  7. docker挂载本地目录和数据卷容器

    1.docker挂载本地目录 docker可以支持把一个宿主机上的目录挂载到镜像里. 交互模式运行docker run -it -v /home/dock/Downloads:/usr/Downloa ...

  8. 查询反模式 - GroupBy和HAVING的理解

    为了最简单地说明问题,我特地设计了一张这样的表. 一.GROUP BY单值规则 规则1:单值规则,跟在SELECT后面的列表,对于每个分组来说,必须返回且仅仅返回一个值. 典型的表现就是跟在SELEC ...

  9. windows 如何查看端口占用进程ID 进程名称 强制结束进程

    1.查看指定端口的占用情况C:\>netstat -aon|findstr "9050" 协议    本地地址                     外部地址        ...

  10. 【转】纵表、横表互转的SQL

    纵表.横表互转的SQL 原文1:http://takkymj.iteye.com/blog/751401   横表就是普通的建表方式,如一个表结构为: 主键.字段1.字段2.字段3... 如果变成纵表 ...