[LeetCode]9. Palindrome Number判断回文数字
/*
查看网上的思路有两种:
1.每次取两边的数,然后进行比较
2.取数的倒置数,进行比较
*/
public boolean isPalindrome1(int x) {
if (x<0) return false;
//以四位数为例,取左边的数用的方法是/1000,取右边的数用的是%10
//注意每次取完两遍要更新数和位数
int len = 1;
int temp = x;
while (temp>=10)
{
len*=10;
temp/=10;
}
while (x!=0)
{
int left = x/len;
int right = x%10;
if (left!=right) return false;
len/=100;
//更新x的方法是先取出后几位,再去掉最右边
//%用来留下后边的,/用来留下前边的
x = (x%len)/10;
}
return true;
}
public boolean isPalindrome2(int x)
{
if (x<0) return false;
int a = 0;
int b = x;
while (b!=0)
{
a = a*10+b%10;
b%=10;
}
return (a==x);
}
[LeetCode]9. Palindrome Number判断回文数字的更多相关文章
- Leetcode 9. Palindrome Number(判断回文数字)
Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...
- LeetCode 9 Palindrome Number(回文数字判断)
Long Time No See ! 题目链接https://leetcode.com/problems/palindrome-number/?tab=Description 首先确定该数字的 ...
- 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. An integer is a palindrome when it reads the same back ...
- 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字
我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...
- [LeetCode] Palindrome Number 验证回文数字
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- [Leetcode] Palindrome number 判断回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- LeetCode OJ Palindrome Number(回文数)
class Solution { public: bool isPalindrome(int x) { ,init=x; ) return true; ) return false; ){ r=r*+ ...
- LeetCode 9. Palindrome Number(回文数)
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same back ...
随机推荐
- 自动化运维工具之Puppet常用资源(一)
前文我们聊到了puppet的架构,单机模型和master/agent模型的工作流程以及puppet的基础使用,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/14 ...
- centOs7.5.64以上版本的操作系统搭建GitLab记录
一. 安装并配置必要的依赖关系在CentOS系统上安装所需的依赖:ssh,防火墙,postfix(用于邮件通知) ,wget,以下这些命令也会打开系统防火墙中的HTTP和SSH端口访问. 1.安装ss ...
- Windows 10系统运维之OpenSSH
随着PowerShell和OpenSSH的日渐成熟,在客户终端Windows居多的运维之中,使用Win32-OpenSSH和Powershell来管理一些客户机变成了相当实用的一种解决方案. Open ...
- 微软发布 Pylance:改善 VS Code 中的 Python 体验
原标题:微软发布 Pylance:改善 VS Code 中的 Python 体验 来源:开源中国 微软宣布推出一种新的 Python 语言服务器,名为 Pylance,其可利用语言服务器协议与 VS ...
- MySQL错误日志(Error Log)
错误日志是一个文本文件,记录了 MySQL Server 每次启动和关闭的详细信息以及运行过程中所有较为严重的警告和错误信息.在遇到问题时,应该首先查看这个文件. 如何开启 使用命令 SHOW VAR ...
- 老猿学5G扫盲贴:3GPP规范中部分与计费相关的规范序列文档
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 经咨询华为公司的相关专家,以及结合3GPP目录下载 ...
- 第14章 web前端开发小白学爬虫结束语
老猿学爬虫应该是2019年7月初开始的,到现在2个多月了,有段时间了,这部分一直是老猿期待能给大家带来收获的,因为老猿爬虫实战应用的场景与网上老猿已知的场景基本都不一样,是从复用网站登录会话信息来开发 ...
- Mysql 逻辑架构图及日志系统
我们经常能看到如下的逻辑架构图,但是往往不能进行很好的记忆,看过就忘记了,也不知道它的实现方式.今天通过简单的画图来简单了解一下mysql到底是如何执行一个select语句,如何update一条语句. ...
- 1、pytorch写的第一个Linear模型(原始版,不调用nn.Modules模块)
参考: https://github.com/Iallen520/lhy_DL_Hw/blob/master/PyTorch_Introduction.ipynb 模拟一个回归模型,y = X * w ...
- ActionResult的返回类型
ActionResult是控制器方法执行后返回的结果类型,控制器方法可以返回一个直接或间接从ActionResult抽象类继承的类型,如果返回的是非ActionResult类型,控制器将会将结果转换为 ...