原题链接:https://leetcode.com/problems/palindrome-number/description/

1. 题目要求:判断一个int类型整数是否是回文,空间复杂度O(1)

2. 注意:负数不是回文!!因为前面有负号!注意整数溢出问题。

3. 思路:依然采用取余取整的方法

 package com.huiAlex;

 public class PalindromeNumber3 {
public static void main(String[] args) {
PalindromeNumber3 pn = new PalindromeNumber3();
System.out.println(pn.isPalindrome(-12321));
System.out.println(pn.isPalindrome(-2147483648));
System.out.println(pn.isPalindrome(2147447412));
} public boolean isPalindrome(int x) {
// 负数不是回文!!!
if (x < 0) {
return false;
}
int num = x;
System.out.println(num);
int result = 0;
while (num != 0) {
if (result > (Integer.MAX_VALUE - num % 10) / 10) {
return false;
}
result = result * 10 + num % 10;
num = num / 10;
}
if(x>0){ }else {
x = -x;
}
if (result == x) {
return true;
} else {
return false;
}
}
}

LeetCode:9. Palindromic Number(Medium)的更多相关文章

  1. LeetCode:39. Combination Sum(Medium)

    1. 原题链接 https://leetcode.com/problems/combination-sum/description/ 2. 题目要求 给定一个整型数组candidates[ ]和目标值 ...

  2. LeetCode:36. Valid Sudoku(Medium)

    1. 原题链接 https://leetcode.com/problems/valid-sudoku/description/ 2. 题目要求 给定一个 9✖️9 的数独,判断该数独是否合法 数独用字 ...

  3. LeetCode:43. Multiply Strings (Medium)

    1. 原题链接 https://leetcode.com/problems/multiply-strings/description/ 2. 题目要求 给定两个String类型的正整数num1.num ...

  4. LeetCode:16. 3Sum Closest(Medium)

    1. 原题链接 https://leetcode.com/problems/3sum-closest/description/ 2. 题目要求 数组S = nums[n]包含n个整数,找出S中三个整数 ...

  5. LeetCode:49. Group Anagrams(Medium)

    1. 原题链接 https://leetcode.com/problems/group-anagrams/description/ 2. 题目要求 给定一个字符串数组,将数组中包含相同字母的元素放在同 ...

  6. LeetCode:22. Generate Parentheses(Medium)

    1. 原题链接 https://leetcode.com/problems/generate-parentheses/description/ 2. 题目要求 给出一个正整数n,请求出由n对合法的圆括 ...

  7. PAT 甲级 1019 General Palindromic Number(20)(测试点分析)

    1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...

  8. leetcode:Longest Palindromic Substring(求最大的回文字符串)

    Question:Given a string S, find the longest palindromic substring in S. You may assume that the maxi ...

  9. leetcode:283. Move Zeroes(Java)解答

    转载请注明出处:z_zhaojun的博客 原文地址:http://blog.csdn.net/u012975705/article/details/50493772 题目地址:https://leet ...

随机推荐

  1. 通过一个实际例子理解Kubernetes里pod的自动scale - 水平自动伸缩

    kubectl scale命令用于程序在负载加重或缩小时进行pod扩容或缩小,我们通过一些实际例子来观察scale命令到底能达到什么效果. 命令行创建一个deployment: kubectl run ...

  2. python:包与异常处理

    一.包 1,什么是包? 把解决一类问题的模块放在同一个文件夹里-----包 2,包是一种通过使用‘.模块名’来组织python模块名称空间的方式. 1. 无论是import形式还是from...imp ...

  3. LA 4256 商人

    题目链接:https://vjudge.net/contest/160916#problem/B 题意:给一个无向图,和一个序列:要求,在这个序列中,两两相连的两个数相同,或者,在无向图中相邻:(n& ...

  4. 布局方式-inline-block布局

    .像文本一样排block元素 .没有清除浮动等问题 .需要处理间隙     一种方式 <style> .container{ width: 800px; height: 200px; fo ...

  5. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 【分块】

    任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 ...

  6. 行云管家 V4.7产品新特性-国际化版本、支持Oracle的数据库审计、主机密码自动修改策略 发布日期:2018-11-22

    行云管家在线体验: 行云管家[官网]-领先的云计算管理平台-云安全,堡垒机,自动化运维​ 行云管家新手有礼活动: 行云管家新手有礼,新用户1元即可体验专业版-优惠券​ 发布日期:2018-11-22 ...

  7. 【Linux-CentOS】CentOS安装Win双系统后Win启动项丢失及默认启动项修改

    转载自:搁浅bky,有部分更正,建议看此文. 1.Windows启动项消失的原因:   在安装Win7.8/10系统+CentOS7双系统后,默认会将mbr(Main Boot Record)改写为g ...

  8. jenkins 安装配置: centos-master windows/linux-slave + nginx代理 + node + job

    centos install jenkins: 1.sudo vi /etc/yum.repos.d/jenkins.repo [jenkins] name=Jenkins baseurl=http: ...

  9. SpringBoot非官方教程 | 终章:文章汇总

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot-all/ 本文出自方志朋的博客 SpringBo ...

  10. java中静态代理和动态代理

    一.概述 代理是一种模式,提供了对目标对象的间接访问方式,即通过代理访问目标对象.如此便于在目标实现的基础上增加额外的功能操作,前拦截,后拦截等,以满足自身的业务需求,同时代理模式便于扩展目标对象功能 ...