【leetcode】 Reverse Integer
2015-03-16 23:02
351 查看
问题描述:
问题考虑:
1.考虑逆转越界的问题
其余思路常规题解法~
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321
问题考虑:
1.考虑逆转越界的问题
其余思路常规题解法~
public int reverse(int x) { int temp=0; int sign=1; if(x==Integer.MIN_VALUE) return 0; if(x<0){ x=-x; sign=-1; } while(x!=0){ if(temp>Integer.MAX_VALUE/10 ) return 0; temp=temp*10+x%10; x=x/10; //注意这里不能写成 temp*10>Integer.MAX_VALUE,不然temp*10也越界了; } return temp*sign; }
相关文章推荐
- Leetcode 7 Reverse Integer
- C实现 LeetCode->Reverse Integer
- [LeetCode]题解(python):007-Reverse Integer
- LeetCode | 7. Reverse Integer
- Java [leetcode 7] Reverse Integer
- LeetCode —— Reverse Integer
- leetcode-7 Reverse Integer
- Leetcode-Reverse Integer
- leetcode[7]Reverse Integer
- leetcode_7_Reverse Integer
- Leetcode 数 Reverse Integer
- leetcode python - Reverse Integer
- LeetCode | Reverse Integer
- LeetCode1 Reverse Integer
- [LeetCode] Reverse Integer
- 【leetcode】Reverse Integer
- LeetCode: missing num, count of 1s, roman to/from integer, decode ways, reverse integer
- leetcode - Reverse Integer
- Leetcode: Reverse Integer
- 【leetcode】Reverse Integer