leetcode Reverse Integer(Java)
2017-06-11 22:53
281 查看
题目链接:点击打开链接
类型:数学运算
解法:移位运算
public class Solution {
public int reverse(int x) {
long result = 0;
boolean negative = false;
if (x < 0)
{
x = -x;
negative = true;
}
while (x > 0)
{
result = result * 10 + x % 10;
x = x / 10;
}
if (negative)
result = -result;
result = (result > Integer.MAX_VALUE || result < Integer.MIN_VALUE)?0:result;
return (int)result;
}
}
类型:数学运算
解法:移位运算
public class Solution {
public int reverse(int x) {
long result = 0;
boolean negative = false;
if (x < 0)
{
x = -x;
negative = true;
}
while (x > 0)
{
result = result * 10 + x % 10;
x = x / 10;
}
if (negative)
result = -result;
result = (result > Integer.MAX_VALUE || result < Integer.MIN_VALUE)?0:result;
return (int)result;
}
}
相关文章推荐
- LeetCode : Reverse Integer [java]
- 【leetcode】Reverse Integer整数反转----Java代码实现
- leetcode Reverse Integer (Java)
- LeetCode--Reverse Integer (Cpp,Java,Python)
- LeetCode 7 Reverse Integer(C,C++,Java,Python)
- Reverse Integer--LeetCode(Java)
- 【LeetCode-面试算法经典-Java实现】【007-Reverse Integer(翻转整数)】
- leetcode:Reverse Integer 【Java】
- leetcode解题之07#Reverse Integer Java版 通过溢出测试
- LeetCode【7】.Reverse Integer--java实现
- 【LeetCode7】【Reverse Integer】java中整形正负表示的一些思考
- leetcode Reverse Integer java基本编程学习笔记(一)
- [LeetCode][7]Reverse Integer解析与位运算实现 -Java实现
- Reverse Integer leetcode java
- leetCode --Reverse Integer以及java基本类型
- LeetCode 7 — Reverse Integer(C++ Java Python)
- Reverse Integer Leetcode Python Java
- [Leetcode] Reverse Integer (Java)
- Reverse Integer LeetCode Java
- LeetCode 7 : Reverse Integer (Java)