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 ...
随机推荐
- 个人文件转移工具-来自某位大神的C盘清理神器
软件名称:个人文件转移工具 软件功能:文件转移 支持平台:Windows 软件简介:一款文件转移工具,也可用作C盘瘦身. 软件特点: ◉ "个人文件转移工具"可以把"我的 ...
- Refit 原理解析:从初识到实践
在现代的分布式系统和微服务架构中,HTTP API 调用是不可或缺的一部分.为了简化 HTTP 请求的构建和解析,我们可以使用 Refit 这个强大的库.Refit 通过将 HTTP API 抽象为接 ...
- 常见的各类LLM基座模型(GPT、DeepSeek、Qwen等)模型解析以及对比
From: https://www.big-yellow-j.top/posts/2025/02/15/LLM.html 各类LLM模型技术汇总 只去对比整体框架,对所采用的激活函数,归一化处理,位置 ...
- 少样本学习实战:Few-Shot Prompt设计
让AI用最少样本学会"举一反三" 想象一下,你要教一个外星人认识地球上的动物.如果只给它看三张哈士奇的照片,它可能会认为所有四条腿的动物都叫"哈士奇".这就是A ...
- 【记录】C/C++-关于I/O的坑与教训
吐槽 每每读取字符串时,倘若稍有灵活的操作,总会遇上诡异奇怪的事情.究其原因,就是没完全理解一些基本读写函数的机制.这次做Uva227就把I/O上的问题全暴露出来了.想来还是应该记录一些经验教训. 记 ...
- go ceph s3文件管理
导入依赖 go get gopkg.in/amz.v1/aws go get gopkg.in/amz.v1/s3 创建用户 在初始化连接之前,我们需要创建一个用户得到accessKey和secret ...
- goframe API 自定义接口返回值处理
前言 goframe 默认使用了中间键 ghttp.MiddlewareHandlerResponse, HTTP Server 的数据返回通过 ghttp.Response 对象实现,ghttp.R ...
- Invalid prop: type check failed for prop "showCheckbox". Expected Boolean, got String.
一个简单的报错 ,可以用于 代码: <el-tree :data="menus" :props="defaultProps" ...
- 【Python】Python环境安装与简单代码运行
Python环境安装与简单代码运行 视频教程链接:https://www.bilibili.com/video/BV1KG4y1t7dM/ 一.配置Python环境 1.下载Python安装包 建议使 ...
- wpf关于设备无关性的理解
wpf的像素单位是1/96*系统dpi.当前系统dpi是96,那么wpf的一个单位长就是1px像素.这个系统dpi的意思就是物理单位一英寸里有多少个像素点,比如windows标准的96dpi,意味着一 ...