//原题链接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进阶路⑨的更多相关文章

  1. Palindrome Number - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Palindrome Number - LeetCode 注意点 负数肯定是要return false的 数字的位数要分奇数和偶数两种情况 解法 解法一: ...

  2. Palindrome Number leetcode java

    题目: Determine whether an integer is a palindrome. Do this without extra space. click to show spoiler ...

  3. Palindrome Number ---- LeetCode 009

    Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...

  4. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...

  5. leetcode bug & 9. Palindrome Number

    leetcode bug & 9. Palindrome Number bug shit bug "use strict"; /** * * @author xgqfrms ...

  6. 【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 ...

  7. leetcode 第九题 Palindrome Number(java)

    Palindrome Number time=434ms 负数不是回文数 public class Solution { public boolean isPalindrome(int x) { in ...

  8. leetcode题解 9. Palindrome Number

    9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...

  9. leetcode:Reverse Integer 及Palindrome Number

    Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...

  10. 【LeetCode】9. Palindrome Number (2 solutions)

    Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...

随机推荐

  1. docker - [02] 安装部署

    一.环境准备 1.需要会一点点Linux基础 2.CentOS 7+ 3.XShell连接服务器进行远程操作 Centos7.x 虚拟机环境 序号 主机名 IP 操作系统 1 ctos79-01 19 ...

  2. 【Azure Fabric Service】分享使用Visual Studio 2022发布中国区Service Fabric服务应用的办法

    问题描述 使用Visual Studio 2022如何发布Service Fabric到中国区云服务呢? 因为使用VS2022中的插件无法创建Service Fabric Cluster服务. 那么, ...

  3. c#数据库操作ORM映射框架

    主要功能介绍 支持Oracle,SQL Server,MySQL,SQLLite等数据库..主要功能: 支持查询返回动态类型Dynamic以及可扩展类型ExpandoDynamic 表拆分,根据某个日 ...

  4. 【SpringMVC】映射请求参数 & 请求头

    映射请求参数 & 请求参数 请求处理方法签名 Spring MVC 通过分析处理方法的签名,将 HTTP 请求信息绑定到处理方法的相应人参中. Spring MVC 对控制器处理方法签名的限制 ...

  5. This APT has Super Cow Powers.

    在Debian/Ubuntu上,apt包管理器内嵌着一个彩蛋. 如果你在命令行界面输入 apt help 在最后一行能找到This APT has Super Cow Powers. 说明该apt具有 ...

  6. python的typer写cli脚本如此简单

    # typer_demo.py import typer from pathlib import Path from typing import Optional from typing_extens ...

  7. Web前端入门第 27 问:你知道 CSS 被浏览器分为了几大类吗?

    埋头苦写多年的 CSS,从没注意到 CSS 被浏览器分了类,直到偶然的一次翻阅开发者工具,才发现原来 CSS 属性也被浏览器归类收纳了. Chrome 下面是 Chrome 的开发者工具中 CSS 的 ...

  8. HTB打靶记录-Administrator

    # 信息收集 nmap -sV -sC -O 10.10.11.42 Nmap scan report for 10.10.11.42 Host is up (0.70s latency). Not ...

  9. Python科学计算系列9—逻辑代数

    1.基本定理的验证 代码如下: from sympy import * A, B, C = symbols('A B C') # 重叠律 # A·A=A A+A=A print(to_cnf(A | ...

  10. java 限流

    题记 在高并发的分布式系统中,我们都需要考虑接口并发量突增时造成的严重后果,后端服务的高压力严重甚至会导致系统宕机.为避免这种问题,我们都会为接口添加限流.降级.熔断等能力,从而使接口更为健壮. 限流 ...