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 ...
随机推荐
- MySQL - [18] mysql中关于cascade的用法
drop database语句用于删除数据库.但如果想要删除一个数据库并且还要删除所有依赖于该数据库的存储过程.函数等,可以使用cascade关键字.drop database test cascad ...
- Redis高可用部署:3台服务器打造哨兵集群
1.Redis集群介绍 Redis 集群(Redis Cluster)是Redis提供的一种分布式部署方式,旨在提供高可用性.如果某个主节点发生故障,集群能够自动进行故障转移,将副本提升为主节点,从而 ...
- 探秘Transformer系列之(9)--- 位置编码分类
探秘Transformer系列之(9)--- 位置编码分类 目录 探秘Transformer系列之(9)--- 位置编码分类 0x00 概述 0x01 区别 1.1 从直观角度来看 1.2 从模型处理 ...
- 青岛oj集训1
2025/3/4 内容:有向无环图(DAG) 优点:DAG有很多良好性质 拓扑排序 用处:可以根据拓扑序进行dp 这次计算所用的所有边的权值都是有计算过的 一张DAG图肯定有拓扑序(bfs序,dfs序 ...
- 李沐动手学深度学习V2-chapter_linear-networks
李沐动手学深度学习V2 文章内容说明 本文主要是自己学习过程中的随手笔记,需要自取 课程参考B站:https://space.bilibili.com/1567748478?spm_id_from=3 ...
- 多机器的键鼠互通——Synergy/Deskflow配置记录
Synergy (1.14.6) 情况一样,那么感觉就是机器之间TCP连接有问题,测试不同 一些测试命令 ss -tlnp | grep 24800 # 查看端口情况 sudo lsof -i :24 ...
- Go是怎么解决包依赖管理问题的?
我们先来了解一下 Go 构建模式的演化过程,弄清楚 Go 核心开发团队为什么要引入 Go module 构建模式. Go 构建模式时怎么演化的? Go 程序由 Go 包组合而成的,Go 程序的构建过程 ...
- 归并排序(递归)(NB)
博客地址:https://www.cnblogs.com/zylyehuo/ 递归思路 # _*_coding:utf-8_*_ import random def merge(li, low, mi ...
- wait、notify、notifyAll的理解与使用
基础知识 Java 中,可以通过配合调用 Object 对象的 wait() 方法和 notify() 方法或 notifyAll() 方法来实现线程间的通信. 在线程中调用 wait() 方法,将阻 ...
- 深度剖析 StarRocks 读取 ORC 加密文件背后的技术
作者:vivo 互联网大数据团队 - Zheng Xiaofeng 本文介绍了StarRocks数据库如何读取ORC加密文件,包括基础概念以及具体实现方案.深入探讨了利用ORC文件的四层结构和三层索引 ...