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. React Diff 算法

    React介绍 React是Facebook开发的一款JS库,用于构建用户界面的类库. 它采用声明式范例,可以传递声明代码,最大限度地减少与DOM的交互. 特点: 声明式设计:React采用声明范式, ...

  2. 程序级的AOP到底好不好?

    很多年前模拟过Spring的AOP机制,简单的实现其实不难,但真正要保证切入代码符合预期的设计,不会引起负面影响,特别是要保证原来逻辑的稳定性,即AOP的强壮性.个人感觉还是很难,如果横切的代码过多, ...

  3. 使用eclipse启动系统时报错“ java.lang.OutOfMemoryError: PermGen space”问题的解决

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/76571611 本文出自[我是干勾鱼的博客] 有的时候,使用eclipse启动系统 ...

  4. BZOJ3296:Learning Languages(简单并查集)

    3296: [USACO2011 Open] Learning Languages Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 436  Solved ...

  5. 为什么要使用索引?-Innodb与Myisam引擎的区别与应用场景

    Innodb与Myisam引擎的区别与应用场景 http://www.cnblogs.com/changna1314/p/6878900.html https://www.cnblogs.com/ho ...

  6. table 如何给tr border颜色

    border-collapse属性值 说明 separate 默认值,边框分开,不合并 collapse 边框合并,如果相邻,则共用一个边框 table,th,td{border:1px solid  ...

  7. Hive之 hive与rdbms对比

    对比图 总结: Hive并非为联机事务处理而设计,Hive并不提供实时的查询和基于行级的数据更新操作.Hive是建立在Hadoop之上的数据仓库软件工具,它提供了一系列的工具,帮助用户对大规模的数据进 ...

  8. spring下的多线程

    链接 1,http://haidaoqi3630.iteye.com/blog/1920944 2,http://www.importnew.com/27440.html .............. ...

  9. 简单桶排序算法-python实现

    #-*- coding: UTF-8 -*- import numpy as np def BucketSort(a, n): barrel = np.zeros((1, n), dtype = 'i ...

  10. PowerDesigner如何将消失的工具栏显示出来

    工具Tool->自定义工具栏,在弹出窗口中选中Palette,并点击[Close]关闭窗口.