【Leetcode009】Palindrome Number
问题链接:https://leetcode.com/problems/palindrome-number/#/description
Question:Determine whether an integer is a palindrome. Do this without extra space.
题意:判断一个数是否是回文数,不使用额外的空间。
分析:直接算出数字的倒序与该数字比较即可。
代码:
C++版
class Solution {
public:
bool isPalindrome(int x) {
;
int originalNumber = x;
){
return false;
}
){
newNumber = originalNumber% + newNumber*;
originalNumber /= ;
}
if(newNumber == x){
return true;
}else{
return false;
}
}
};
Python版:
class Solution:
# @return a boolean
def isPalindrome(self, x):
return str(x) == str(x)[::-1]
【Leetcode009】Palindrome Number的更多相关文章
- 【leetcode】Palindrome Number
题目简述: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could n ...
- 【leetcode】Palindrome Number (easy)
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- 【Leetcode】【Easy】Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. 判断一个整数是不是回文整数(例12321).不能使 ...
- 【LeetCode9】Palindrome Number★
题目描述: 解题思路: 求回文数,并且要求不能使用额外的空间.思路很简单,算出x的倒置数reverse,比较reverse是否和x相等就行了. Java代码: public class LeetCod ...
- 【Leetcode-easy】Palindrome Number
思路:除和求余 取得首位和末尾 比较是否相等. public boolean isPalindrome(int x){ if(x<0){ return false; } int div=1; w ...
- 【LeetCode】Palindrome Number(回文数)
这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...
- 【POJ2104】【HDU2665】K-th Number 主席树
[POJ2104][HDU2665]K-th Number Description You are working for Macrohard company in data structures d ...
- 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)
[SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...
- 【CF932G】Palindrome Partition(回文树,动态规划)
[CF932G]Palindrome Partition(回文树,动态规划) 题面 CF 翻译: 给定一个串,把串分为偶数段 假设分为了\(s1,s2,s3....sk\) 求,满足\(s_1=s_k ...
随机推荐
- Weex 解析(二)—— NativeBridge
(本篇幅主要讲解Weex 中iOS native与js交互实现) 大纲: weex 总框架预览 iOS NativeBridge总设计原理 一.weex 总框架预览 在写NativeBridge 总设 ...
- imageView添加阴影和边框
注意:大量设置阴影会造成卡顿!!! 用上这句之后流畅度大大增加:imageV.layer.shouldRasterize = YES; 例: // 设置阴影 imageV.layer.shadowOf ...
- HttpContext.Current.Cache和HttpRuntime.Cache的区别,以及System.Runtime.Caching
先看MSDN上的解释: HttpContext.Current.Cache:为当前 HTTP 请求获取Cache对象. HttpRuntime.Cache:获取当前应用程序的Cac ...
- [转]你真的了解setTimeout和setInterval吗?
原文: http://qingbob.com/difference-between-settimeout-setinterval/ setTimeout和setInterval的基本用法我们一带而过: ...
- shell查看执行过程及时间变量
sh -xv test.sh #加参数xv查看shell执行过程. Shell 调用系统时间变量 获取今天时期:`date +%Y%m%d` 或 `date +%F` 或date +%Y-%m- ...
- windows抓包工具Wireshark(过滤)
1.IP过滤 ip.src ==192.168.0.208(ip.src eq 192.168.0.208) //来源等于某个ip ip.dst ==192.168.0.208(ip.dst eq 1 ...
- Windows修改MySQL用户root密码
MySQL是一个关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软 ...
- 用cascade删除有约束的表或记录
删除有约束的表 Drop table TERMPRO_RULE_ROUTE_TYPE cascade constraints:
- 关于Pycharm中如何注释
主要有三种方法: ①在程序行前面加“#” ②将需要注释的代码用'''----''' 包起来,此方法类似C的注释方法 ③将需要注释的代码选住然后利用“Ctrl+/”进行注释 # test=input(' ...
- Android使用图表库简单教程
经常要用到统计数据这个功能,要直观的显示出来,最好还是用图表.自己弄也麻烦,所以用了Github上的一个非常著名的开源图标库:MpChart. 使用前去网上找它俩的jar包,然后导入就行.资源比较好找 ...