leetcode题解 9. Palindrome Number
9. Palindrome Number
题目:
Determine whether an integer is a palindrome. Do this without extra space.
Could negative integers be palindromes? (ie, -1)
If you are thinking of converting the integer to string, note the restriction of using extra space.
You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
There is a more generic way of solving this problem.
其实就是判断一个数字是不是回文数字。
一开始的思路是找到开始的数字和最后的数字进行比对,发现自己有点天真,哈哈哈,又不是字符串啦,不好比较。
正确的思路就是求出它的相反的那个数,然后判断他们两是不是相等的。
负数的情况感觉应该特判一下都不是回文,没有特判也过了,下面是代码:
class Solution {
public:
bool isPalindrome(int x) {
int reverse=;
int temp=x;
while(temp>)
{
reverse=reverse*+temp%;
temp=temp/;
}
if(x==reverse)
return true;
else
return false;
}
};
leetcode题解 9. Palindrome Number的更多相关文章
- [LeetCode 题解]:Palindrome Number
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Determine ...
- 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字
我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...
- leetcode bug & 9. Palindrome Number
leetcode bug & 9. Palindrome Number bug shit bug "use strict"; /** * * @author xgqfrms ...
- leetcode 第九题 Palindrome Number(java)
Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...
- 【LeetCode】9. Palindrome Number (2 solutions)
Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...
- C# 写 LeetCode easy #9 Palindrome Number
9.Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome when it ...
- 【LeetCode】9. Palindrome Number 回文数
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...
- LeetCode(9) - Palindrome Number
题目要求判断一个整数是不是回文数,假设输入是1234321,就返回true,输入的是123421,就返回false.题目要求in-place,思路其实很简单,在LeetCode(7)里面我们刚好做了r ...
- 【一天一道LeetCode】#9. Palindrome Number
一天一道LeetCode系列 (一)题目 Determine whether an integer is a palindrome. Do this without extra space. Some ...
随机推荐
- Django的admin相关
自定义admin展示的内容 根据之前已经创建好了的models from django.db import models class Person(models.Model): name = mode ...
- 现代 PHP 新特性 —— 生成器入门(转)
原文链接:blog.phpzendo.com PHP 在 5.5 版本中引入了「生成器(Generator)」特性,不过这个特性并没有引起人们的注意.在官方的 从 PHP 5.4.x 迁移到 PHP ...
- 美团2017年CodeM大赛-初赛B轮-黑白树
https://ac.nowcoder.com/acm/problem/13249 链接:https://ac.nowcoder.com/acm/problem/13249来源:牛客网 题目描述 一棵 ...
- sql 2012 用户sa登陆不上
1.通过Windows身份验证进入服务器 2.点击“安全性”--“登录名”--“sa” 3.右击sa,点击“属性” 4.取消“强制实施密码策略(F)”勾选 5.对密码重新输入 6.点击确定,重新用SQ ...
- MySQL—概念,用户的创建,主键,外键,数据类型,表格创建
MySQL DBMS,MySQL的概念,数据库分类,以前MySQL的部署中的一些概念 #DBMS:数据库管理系统,用于管理数据库的大型软件.mysql就是dbms的一种 #Mysql:是用于管理文件的 ...
- js的回调函数
介绍首先从英文介绍开始 A callback is a function that is passed as an argument to another function and is execut ...
- Android 音视频深入 二十一 FFmpeg视频剪切
视频剪切我意外的发现上一次的视频压缩的代码能够运行FFmpeg视频剪切的命令,但是不能做视频合并的命令,因为不能读取记录了几个视频的路径的txt文件. 这里我就说直说视频剪切的过程,不说代码,只说lo ...
- 一个通过GINA拦截 盗窃登陆口令的病毒分析
病毒行为: 1\将资源中的DLL释放到当前目录下 2\设置注册表,将GINA DLL设置为上一步中释放的DLL DLL行为: 1\在DLL被进程装载时, 装载正常的msgina.dll, 并保存句柄, ...
- ios打包unity应用以及配置签名
先决条件是必须为苹果mac机.拥有公司苹果账号,并确保电脑上安装了unity,unity包 ios-support.和xcode. 1.打开了unity应用之后,选择buildSettings 然后点 ...
- Lambda为什么又称为匿名函数
用法: 有的类,里面只有一个方法,几行代码,只使用一次,以后再不会用到这个类,那就不值当的单独创建一个类,此时使用匿名内部类 一.传统方式 1.接口 2.接口实现类 创建一个类,这个类可能被多次使用, ...