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 ...
随机推荐
- [GXOI/GZOI2019]旧词
很像LNOI 2014 LCA那道题. 同样的套路,离线以后直接扫描线. k=1的话就是原题. 考虑一般情况. 原本的做法是对x到根的这条链做一下区间+1操作,目的是为了是的在深度为i的位置得到的贡献 ...
- MariaDB主从复制,redis发布订阅,持久化,以及主从同步
一. MariaDB主从复制 mysql基本操作 1 连接数据库 mysql -u root -p -h 127.0.0.1 mysql -u root -p -h 192.168.12.60 2 ...
- Python----unittest discover()方法与执行顺序
一.Unittest discover()可以根据不同的功能创建不同的测试文件,甚至是不同的测试目录,测试文件中还可以将不同的小功能划分为不同的测试类,在类下编写测试用例,让整体结构更加清晰一般是通过 ...
- 用html和css制作奥运五环
<html><head><meta charset="utf-8"> <style>.circle1,.circle2,.circl ...
- js 实现异步上传图片+预览
两种js实现方式,一种用原生的ajax:另一种用JQuery,例子比较简单,直接上代码. <!DOCTYPE html> <html> <head> <tit ...
- python day1 之三级菜单的正确姿势
看了几个同学有关三级菜单的实现,都是通过一级一级输出,是较为过程的实现.另外如果菜单(树形结构)更多级这样处理起来就比较麻烦了. 可以使用python强大的列表和字典,实现的更优美或简洁一些: 注:复 ...
- Spring AOP 的实现机制
作者:大名Dean鼎 http://www.importnew.com/28342.html AOP(Aspect Orient Programming),一般称为面向切面编程,作为面向对象的一种补充 ...
- session和cookie的区别是什么,他们都是什么.
Session是存储在服务器端的,Cookie是存储在客户端的. Cookie是客户端保存用户信息的一种机制,用来记录用户的一些信息.如何识别特定的客户呢?cookie就可以做到.每次HTTP请求时, ...
- 用VS2017编写C语言的Hello World
1.新建项目 2.选择新建空项目 3.在源文件处右键单击,选择添加-新建项 4.选择“c++文件”,将名称后缀改成.c即可用C语言编写程序 5.编写代码: #include <stdio.h&g ...
- JS JQ 深拷贝之坑
之前做留言板的时候,我就被深拷贝坑了一次,这次做API管理系统,没想到又被深拷贝坑了一次. 最后,拷贝对象的时候,如果要用到对象里的prototype,一定要用$.extend(true,{},要拷贝 ...