原题链接: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. 抓取android系统日志_记录一次定位app闪退故障

    在测试android客户端兼容性时,发现app闪退,上海的小伙伴需要闪退时的系统日志:故把快生锈的adb知识拿出来show一把: 1.下载adb工具包(adb的全称为Android Debug Bri ...

  2. 利物浦VS曼城,罗指导的先手与工程师的后手

      本想『标题党』一下的,『高速反击遭遇剧情反转,巴西人力挽狂澜绝处逢生!』这种好像看起来比较厉害的标题似乎在大战之后的第五天已显得不合适了. /不害臊    反正晚了,干脆写点能够引起讨论.并且在未 ...

  3. Visual Stuio 2010 常用快捷及操作

    1.如果你想复制一行代码(超级长,鼠标拖老久的),只需要在这行的空白处 CTRL+C 同理,剪贴一行 CTRL+X 删除一行 CTRL+L 2.显示方法里的参数,以前每次都是手动删括号. CTRL+S ...

  4. Error: Error SSL Required Code: 403

    Error: Error SSL Required Code: 403 Error Message If the 'services' Web directory for ArcGIS is set ...

  5. 学大伟业 Day 6 培训总结

    今天接着昨天的继续讲数据结构 今天先是 分块 在统计问题中,尤其是序列问题,经常涉及到区间的操作,比如修改一段区间的元素,询问某个区间的元素的信息. 如果每次都对一整个区间的每一个元素进行操作的话,那 ...

  6. echarts图标相关

    图标类型参考地址: http://echarts.baidu.com/echarts2/doc/doc.html 知识点一: 堆叠柱状图与普通柱状图的区别在于: 堆叠柱状图 在series中需要设置  ...

  7. SpringBoot非官方教程 | 第十一篇:springboot集成swagger2,构建优雅的Restful API

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

  8. File zilla远程连接服务器报错:服务器发回了不可路由的地址,使用服务器地址代替

    百度的答案都是:更改Filezilla设置,编辑-设置-连接-FTP-被动模式,将“使用服务器的外部ip地址来代替”改为“回到主动模式”即可.但问题没有解决!!! 由于使用的是阿里云的服务器.安全组里 ...

  9. nodejs+express开发blog(1)

    前言 Nodejs是一个年轻的编程框架,充满了活力和无限激情,一直都在保持着快速更新.基于Nodejs的官方Web开发库Express也在同步发展着,每年升级一个大版本,甚至对框架底层都做了大手术.在 ...

  10. 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛--E-回旋星空

    链接:https://www.nowcoder.com/acm/contest/90/E 来源:牛客网 1.题目描述 曾经有两个来自吉尔尼斯的人(A和C)恋爱了,他们晚上经常在一起看头上的那片名为假的 ...