Reverse Integer
2015-07-16 20:20
489 查看
题目:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Have you thought about this?
Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!
If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
Update (2014-11-10):
Test cases had been added to test the overflow behavior.
解体思路:
1.题目是要将一个整形数进行反转;
2.首先需要考虑负数的符号问题,先判断数的正负性,如果是负数将其变为正数利于计算,为了数不超过内存,重新用long定义一个x1变量存储数;
3.运用“%”和“/”进行反转。
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Have you thought about this?
Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!
If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
Update (2014-11-10):
Test cases had been added to test the overflow behavior.
解体思路:
1.题目是要将一个整形数进行反转;
2.首先需要考虑负数的符号问题,先判断数的正负性,如果是负数将其变为正数利于计算,为了数不超过内存,重新用long定义一个x1变量存储数;
3.运用“%”和“/”进行反转。
相关文章推荐
- Leetcode练习- Reverse Integer
- LeetCode_Reverse Integer
- LeetCode-Reverse Integer
- LeetCode 之 Reverse Integer — C++ 实现
- Reverse Integer (LeetCode)
- LeetCode 145 Reverse Integer
- Leetcode: Reverse Integer
- leetcode----Reverse Integer
- LeetCode--Reverse Integer (Cpp,Java,Python)
- [LeetCode]Reverse Integer解题报告
- [leetcode 7] Reverse Integer(整数反转) c函数实现
- leetcode解题之07#Reverse Integer Java版 通过溢出测试
- leetcode 7 --- Reverse Integer
- [LeetCode] 7. Reverse Integer
- LeetCode 7. Reverse Integer C++--带正负号数字反转
- 7. Reverse Integer
- 【python】【leetcode】【算法题目7—Reverse Integer】
- LeetCode 7. Reverse Integer
- Reverse Integer
- LeetCode算法题——Reverse Integer