9.Palindrome Number (INT)
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)的更多相关文章
- 65. Reverse Integer && Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, re ...
- 9. Palindrome Number
/* Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers ...
- No.009 Palindrome Number
9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...
- 【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 ...
- Leetcode 9. Palindrome Number(判断回文数字)
Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...
- leetcode 第九题 Palindrome Number(java)
Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...
- HDU 5062 Beautiful Palindrome Number(数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...
- Reverse Integer - Palindrome Number - 简单模拟
第一个题目是将整数进行反转,这个题实现反转并不难,主要关键点在于如何进行溢出判断.溢出判断再上一篇字符串转整数中已有介绍,本题采用其中的第三种方法,将数字转为字符串,使用字符串比较大小的方法进行比较. ...
- leetcode题解 9. Palindrome Number
9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...
随机推荐
- New Concept English Two 28 76
$课文74 舞台之外 784. An ancient bus stopped by a dry river bed and a party of famous actors and actresse ...
- 【转】Javascript中的this
作者: 阮一峰 日期: 2010年4月30日 this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用.比如, function test(){ ...
- 严重: Dispatcher initialization failed java.lang.RuntimeException: java.lang.reflect.InvocationT
严重: Dispatcher initialization failed java.lang.RuntimeException: java.lang.reflect.InvocationT (2012 ...
- (转)亿级Web系统搭建——单机到分布式集群
当一个Web系统从日访问量10万逐步增长到1000万,甚至超过1亿的过程中,Web系统承受的压力会越来越大,在这个过程中,我们会遇到很多的问题.为了解决这些性能压力带来问题,我们需要在Web系统架构层 ...
- 通过iframe 实现upload file无刷新
<html> <head> </head> <body> <form encType="multipart/form-data&q ...
- 量化投资策略:常见的几种Python回测框架(库)
量化投资策略:常见的几种Python回测框架(库) 原文地址:http://blog.csdn.net/lawme/article/details/51454237 本文章为转载文章.这段时间在研究量 ...
- 使用LINQ获取List列表中的某个字段值
使用LINQ获取列表中的某个字段值,下面以获取员工列表中的编号字段为例子. 1.使用Select方法 List<Emplayee> emplayeeList = GetEmplayeeLi ...
- errno.h的数字对应的字符串错误
#ifndef _I386_ERRNO_H #define _I386_ERRNO_H #define EPERM 1 /* Operation not permitted */ #define EN ...
- linux shell获取用户输入
一.获取用户输入1.基本读取read命令接收标准输入的输入,或其它文件描述符的输入.得到输入后,read命令将数据输入放入一个标准变量中.[root@rac2 ~]# cat t8.sh #!/bin ...
- servlet深探
在spring4下面使用的是ServletContext作为容器,这个是servlet规范里面设置的:加载了默认的servlet(在spring 4之前都是web.xml中做的),但是在spring ...