[LeetCode]Reverse Integer
2014-09-29 22:56
337 查看
题目描述:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
解题方案:
该题比较简单,直接贴代码:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
解题方案:
该题比较简单,直接贴代码:
class Solution { public: int reverse(int x) { //char word[15]; int flag; int result = 0; int count = 1; if( x >= 0){ flag = 1; }else{ flag = -1; x = -x; } while(true){ int temp = x % 10; //cout<<temp<<endl; result = result * count + temp; count = 10; x /= 10; //cout << x<<endl; if(x == 0){ break; } } return flag * result; } };
相关文章推荐
- 【LEETCODE】7-Reverse Integer
- LeetCode 7 Reverse Integer
- leetCode(62)-Reverse Integer
- LeetCode - Reverse Integer
- LeetCode_Reverse Integer
- LeetCode:Reverse Integer
- 【Leetcode】Reverse Integer
- LeetCode--Reverse Integer
- LeetCode -- Reverse Integer
- leetcode007 Reverse Integer
- Leetcode代码学习周记——Reverse Integer
- LeetCode:Reverse Integer
- LeetCode 7 - Reverse Integer
- leetcode----Reverse Integer
- 【LeetCode】Reverse Integer
- LEETCODE 7 Reverse Integer (JAVA题解)
- leetcode:Reverse Integer
- [Leetcode 7, Easy] Reverse integer
- 【LeetCode】7 Reverse Integer
- 【leetcode】7. Reverse Integer