Palindrome Number——LeetCode进阶路⑨
//原题链接https://leetcode.com/problems/palindrome-number/
- 题目描述
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
Input: 121
Output: true
Example 2:
Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
- 思路分析
1.空间复杂度为O(1)
2.负数都不是回文数,返回false
3.利用消消乐想法,末位与首位相同抵消,相异直接返回false - 源码附录
class Solution {
public boolean isPalindrome(int x) {
if(x<0){
return false;
} else{ long temp = 1;
while(temp <= x/10){
temp = temp *10 ;
} while(x>0){
if(x%10 != x/temp){
return false;
}
x = (x % (int)temp)/10;
temp = temp / 100;
}
return true;
}
}
}
Palindrome Number——LeetCode进阶路⑨的更多相关文章
- Palindrome Number - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Palindrome Number - LeetCode 注意点 负数肯定是要return false的 数字的位数要分奇数和偶数两种情况 解法 解法一: ...
- Palindrome Number leetcode java
题目: Determine whether an integer is a palindrome. Do this without extra space. click to show spoiler ...
- Palindrome Number ---- LeetCode 009
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- 《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】9 & 234 & 206 - Palindrome Number & Palindrome Linked List & Reverse Linked List
9 - Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Som ...
- leetcode 第九题 Palindrome Number(java)
Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...
- leetcode题解 9. Palindrome Number
9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...
- leetcode:Reverse Integer 及Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- 【LeetCode】9. Palindrome Number (2 solutions)
Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...
随机推荐
- 【ABAQUS 二次开发笔记】使用keyword 、python和matlab一起处理Odb数据
用conversion shell element (S4R单元)建模层合板,有6层ply,每个lamina(ply)有3个 integration point,共计18个integration po ...
- labelImg 工具介绍
1.什么是labelImg 图片标记工具,生成的xml文件用于人工智能数据 2.怎么使用 打开图片文件夹 使用默认工具tooth 选中图片,快捷键w ,鼠标标记图片 [Ctrl+s] 保存
- How to use the shell, terminal and the advanced tools
How to use the shell, terminal and the advanced tools Introduction Why use English instead of Chin ...
- 云服务器下如何部署Django项目详细操作步骤
前期本人完成了"编写你的第一个 Django 应用程序",有了一个简单的项目代码,在本地window系统自测没问题了,接下来就想办法部署到服务器上,可以通过公网访问我们的Djang ...
- PLSQL中查询数据的时候查询结果显示中文乱码
要需要很努力才能看起来毫不费力.....1.在PLSQL中查询数据的时候查询结果显示中文乱码这里写图片描述2.需要在环境变量中新建两个环境变量:第一个:设置 NLS_LANG=SIMPLIFIED C ...
- postgresql的日期函数
一个to_char干完所有的活.包括日期的转换 函数 返回类型 描述 实例 to_char(timestamp, text) text 将时间戳转换为字符串 to_char(current_times ...
- 本地学习环境minikube安装
有感于K8S太强大和自己的太无知,索性来系统学习下K8S.网上一番攻略,起码先得有个本地学习环境,所以安装一个minikube,下面记录安装过程,供有需要的人使用. 看看minikube架构: 我是在 ...
- .net core基础(一):安装并创建第一个webapi
一..net介绍 .net是一个开发者平台的统称,用它可以构建多种类型的应用程序. .net平台下的开发语言:C#,F#,Visual Basic .net平台标准:.NET Standard .ne ...
- FreeSWITCH中SIP网关(Gateway)操作
freeswitch是一款简单好用的VOIP开源软交换平台. 以下是一篇关于FreeSWITCH中SIP网关(Gateway)操作的技术指南,基于提供的官方文档内容整理: 一.网关生命周期管理 1. ...
- 前端js需要连接后端c#的wss服务
背景前端js需要连接后端wss服务 前端:js后端:c# - 控制台搭建wss服务器 步骤1 wss需要ssl认证,所以需要个证书,随便找一台linux的服务器(windows的话,自己安装下open ...