# leetcode: reverse-integer

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

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?

Throw an exception? Good, but what if throwing an exception is not an option? You would then have to re-design the function (ie, add an extra parameter).

class Solution {

public:
int reverse(int x) {
int r = 0;

for(;x;x/=10)
{
r = r*10+x%10;
}
return r;
}
};

#### leetcode---reverse-integer---复杂度

2018-01-27 10:21:03

#### leetcode — reverse-integer

2018-02-28 09:08:19

#### 4.13 leetcode -13 reverse-integer

2017-08-28 12:58:50

#### 《leetcode》reverse-integer

2017-08-03 13:17:34

#### LeetCode 7 Reverse Integer（翻转整数）

2015-09-23 09:13:52

#### leetcode第7题，Reverse Integer

2017-02-18 20:30:16

#### Reverse-integer

2018-06-19 08:01:42

#### [C++]LeetCode 7:Reverse Integer（翻转整数）

2015-05-02 14:23:48

#### Reverse Integer-python

2018-03-22 10:38:28

#### Leetcode在线编程 reverse-integer

2016-12-11 02:52:14