Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.
分析:把一个数倒过来,然后看两个数是否相同。
public class Solution {
public boolean isPalindrome(int x) {
if (x < ) {
return false;
}
long palindromeX = , inputX = x;
while (x > ) {
palindromeX = palindromeX * + (x % );
x = x / ;
}
return palindromeX == inputX;
}
}
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
public class Solution {
public int reverse(int x) {
boolean isPositive = true;
if (x < ) {
x = -x;
isPositive = false;
}
long reversedValue = ;
while (x != ) {
reversedValue = reversedValue * + x % ;
x /= ;
}
if (Math.abs(reversedValue) > Integer.MAX_VALUE) return ;
return isPositive ? (int)reversedValue : (int)(-reversedValue);
}
}
Palindrome Number的更多相关文章
- 65. Reverse Integer && Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, re ...
- 有趣的数-回文数(Palindrome number)
文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...
- 9. Palindrome Number
/* Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers ...
- No.009 Palindrome Number
9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...
- 【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 ...
- HDU 5062 Beautiful Palindrome Number(数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...
- Reverse Integer - Palindrome Number - 简单模拟
第一个题目是将整数进行反转,这个题实现反转并不难,主要关键点在于如何进行溢出判断.溢出判断再上一篇字符串转整数中已有介绍,本题采用其中的第三种方法,将数字转为字符串,使用字符串比较大小的方法进行比较. ...
- leetcode题解 9. Palindrome Number
9. Palindrome Number 题目: Determine whether an integer is a palindrome. Do this without extra space. ...
- LeetCode--No.009 Palindrome Number
9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...
随机推荐
- LeetCode Intersection of Two Arrays
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...
- Showbo.Msg.alert
注意alert,confirm及prompt并不同于系统的,这个是用层模仿的,并不能挂起程序的执行 所以如果需要在确认后执行相关的操作,需要在配置文件中传递回调函数fn 按钮只提供yes和no两个 S ...
- Microsoft.VisualStudio.TestTools.UnitTesting 命名空间
类 说明 AfterAssemblyCleanupEventArgs 为 AfterAssemblyCleanup 事件提供数据. AfterAssemblyInitializeEventArgs ...
- 关于__int128
定义 __int128 n,r,g,b,T; __int128 ans; __int128 f[][]; 取最大值函数 __int128 getmax(__int128 a,__int128 b){ ...
- 自己写一个JS单向数据流动库----one way binding
JS单向流动其实就是数据到视图的过程, 这几天突发奇想,想着弄一个插件, 把DOM结构使用JS进行描述: 因为DOM中的Class , content, id, attribute, 事件, 子元素全 ...
- android开发之背景音乐与音效
android开发之背景音乐与音效 一:添加背景音乐(MediaPlayer) MediaPlayer class can be used to control playback of audio/v ...
- JavaScript的学习资料
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript http://www.liaoxuefeng.com/wiki/001434446689 ...
- Git for Windows - The Program can't start because libiconv2.dll is missing
今天在新装的win10 预览版上面,发现git不能启动了,提示信息主要是: The Program can't start because libiconv2.dll is missing 于是我在网 ...
- Codeforces Round #342 (Div. 2) A. Guest From the Past(贪心)
传送门 Description Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the detai ...
- 【Beta】Scrum04
Info 由于上次验收基本没有人按时完成,缓冲一个任务周期. 时间:2016.12.06 21:30 时长:25min 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 NXT:2016.12. ...