LeetCode题解——Palindrome Number
题目:
判断一个数字是不是回文数字,即最高位与最低位相同,次高位与次低位相同,...
解法:
求出数字的位数,然后依次求商和求余判断是否相等。
代码:
class Solution {
public:
bool isPalindrome(int x) {
if(x < ) //负数有符号,肯定不是回文数
return false;
int d = ;
while(x / d >= ) //d与x位数相同
d *= ;
while(x)
{
if(x/d != x%) //比较最高位和最低位是否相等
return false;
x = x % d / ; //去掉最高位和最低位
d /= ; //d相应转换
}
return true;
}
};
LeetCode题解——Palindrome Number的更多相关文章
- leetcode题解||Palindrome Number问题
problem: Determine whether an integer is a palindrome. Do this without extra space. click to show sp ...
- Leetcode 9. Palindrome Number(水)
9. Palindrome Number Easy Determine whether an integer is a palindrome. An integer is a palindrome w ...
- Leetcode练习题 Palindrome Number
9. Palindrome Number Question: Determine whether an integer is a palindrome. An integer is a palindr ...
- leetcode 9 Palindrome Number 回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- LeetCode 9. Palindrome Number (回文数字)
Determine whether an integer is a palindrome. Do this without extra space. 题目标签:Math 题目给了我们一个int x, ...
- Leetcode 9. Palindrome Number(判断回文数字)
Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...
- [LeetCode][Python]Palindrome Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/palindr ...
- LeetCode——9. Palindrome Number
一.题目链接:https://leetcode.com/problems/palindrome-number/ 二.题目大意: 给定一个整数,判断它是否为一个回文数.(例如-12,它就不是一个回文数: ...
- 蜗牛慢慢爬 LeetCode 9. Palindrome Number [Difficulty: Easy]
题目 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
随机推荐
- lintcode:Subtree 子树
题目: 子树 有两个不同大小的二叉树: T1 有上百万的节点: T2 有好几百的节点.请设计一种算法,判定 T2 是否为 T1的子树. 样例 下面的例子中 T2 是 T1 的子树: 1 3 / \ / ...
- SpringMVC学习总结(一)——SpringMVC入门
摘要: Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动指的就是使用请求 ...
- dubbo与zookeeper安装手册
原文 示例提供者安装 (+) (#) 安装: wget http://code.alibabatech.com/mvn/releases/com/alibaba/dubbo-demo-provider ...
- ISO9001、ISO14001、OHSAS18000什么意思
ISO9001是ISO9000族标准所包括的一组质量管理体系核心标准之一.ISO9000族标准是国际标准化组织(ISO)在1994年提出的概念,是指“由ISO/TC176(国际标准化组织质量管理和质量 ...
- C++:常类型Const
常类型:使用类型修饰符const说明的类型,常类型的变量或对象成员的值在程序运行期间是不可改变的. 3.10.1 常引用 如果在说明引用时用const修饰,则被说明的引用为常引用.如果用常引用做形参, ...
- Android 在Intent中传递接口
总结:在Activity中不能用intent传递匿名接口,原因如下:Activity A中生成了匿名接口M, 这个接口的引用就在组Activity A中,Activity A会禁止接口M 序列化.因为 ...
- 4、处理方法中获取请求参数、请求头、Cookie及原生的servlet API等
1.请求参数和请求头 使用@RequestParam绑定请求参数,在处理方法的入参处使用该注解可以把请求参数传递给请求方法 —— value :参数名 —— required : 是否必须,默认为tr ...
- python网络爬虫(一):网络爬虫科普与URL含义
1. 科普 通用搜索引擎处理的对象是互联网的网页,目前网页的数量数以亿计,所以搜索引擎面临的第一个问题是如何设计出高效的下载系统,已将海量的网页下载到本地,在本地形成互联网网页的镜像.网络爬虫 ...
- C++ 11 vlearning
1.新增算术类型 longlong,最小不比long小,一般为64位. 2.列表初始化 int units_sold = {0};或者 int units_sold{0};非11标准 ...
- CentOS 6.5系统使用yum方式安装LAMP环境和phpMyAdmin详细过程
介绍如何在CentOs6.2下面使用YUM配置安装LAMP环境,一些兄弟也很喜欢使用编译的安装方法,个人觉得如果不是对服务器做定制,用yum安装稳定简单,何必去download&make&am ...