LeetCode_Reverse Integer
2013-07-26 11:23
281 查看
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321
class Solution { public: int reverse(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function if(x == 0) return x; int flag = 1; if(x < 0) { x*= -1; flag = -1; } vector<int> result; while(x) { int temp = x %10; result.push_back(temp); x/=10; } int num = 0; for(int i = 0; i< result.size(); i++) { num +=result[i]; num*=10; } return flag*num/10 ; } };
相关文章推荐
- Leetcode - Basic - Reverse Integer
- LeetCode (2). Reverse Integer
- LeetCode(5):Reverse Integer
- LCP007 LeetCode 7 Reverse Integer
- LeetCode 7 : Reverse Integer
- LeetCode 007 Reverse Integer
- [LeetCode][Java] Reverse Integer
- LeetCode | Reverse Integer
- Leetcode-7 Reverse Integer
- [Leetcode]Reverse Integer
- LeetCode 7.Reverse Integer
- Leetcode: Reverse Integer
- [LeetCode] Reverse Integer
- leetcode-Reverse Integer
- LeetCode-Reverse Integer
- [LeetCode]Reverse Integer
- LeetCode题目_Reverse Integer
- leetcode-7- Reverse Integer
- [leetcode刷题系列]Reverse Integer
- Leetcode---Reverse Integer