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 ...
随机推荐
- hdu 1978 How many ways
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ...
- SpingMVC中利用BindingResult将错误信息返回到页面中
SpingMVC中利用BindingResult将错误信息返回到页面中. ActionFrom中: private String name; private String password; get( ...
- compiler 学习
一款强大的编译器LLVM:http://llvm.org/docs/GettingStarted.html#layout http://llvm.org/docs/LangRef.html http: ...
- eclipse安装反编译插件
1. 进入http://jadclipse.sourceforge.net/wiki/index.php/Main_Page#Download 下载 net.sf.jadclipse ...
- python os.stat() 和 stat模块详解
stat 系统调用时用来返回相关文件的系统状态信息的. 首先我们看一下stat中有哪些属性: >>> import os >>> print os.stat(&qu ...
- Android设置TextView显示一行或多行
在listView的item中或者是特殊的业务需求中,会要求TextView的内容不完全显示,只有通过一个指定的操作后才显示所有的,比如说一个按钮或者是其它的什么控件. 要想实现这个效果并不难,只要控 ...
- 使用Maven创建一个Spring MVC Web 项目
使用Maven创建java web 项目(Spring MVC)用到如下工具: 1.Maven 3.2 2.IntelliJ IDEA 13 3.JDK 1.7 4.Spring 4.1.1 rele ...
- android logcat里面AndroidRuntime FATAL EXCEPTION: main这个是什么问题啊。
android logcat里面AndroidRuntime FATAL EXCEPTION: main这个是什么问题啊. http://zhidao.baidu.com/link?url=mUI11 ...
- ios 使用GCD 多线程 教程
什么是GCD Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法.该方法在Mac OS X 10.6雪豹中首次推出,并随后被引入到了iOS4.0中.GCD ...
- Collection_Compare
冒泡 package com.bjsxt.sort.bubble; import java.util.Arrays; public class BubbleSort1 { /** * @param a ...