# 【leetcode-7】Reverse Integer(C语言)

Reverse digits of an integer.

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

int reverse(int x) {
bool negative = false;
if(x<0){
negative = true;
x = -x;
}
int nums = 0;
int tmpNum;
int tmp;
int i;
while(x){
tmpNum = nums;
tmp = 0;
for(i = 0;i<10;i++){
tmp = tmp+tmpNum;
if(tmp<tmpNum)
return 0;
}
nums = tmp;
nums=nums+x%10;
x = x/10;
}
if(negative)
return -1*nums;
return nums;
}

int reverse(int x) {
bool negative = false;
if(x<0){
negative = true;
x = -x;
}
int nums = 0;
int tmpNum;
int tmp;
int i;
while(x){
if(nums>(INT_MAX-x%10)/10)//成立，则一定会超
return 0;
nums=nums*10+x%10;
x = x/10;
}
if(negative)
return -nums;
return nums;
}

#### leetcode 7. Reverse Integer（C语言，翻转一个整数，判断是否溢出）19

2017-10-01 21:04:41

#### LeetCode::Reverse Integer C语言

2015-03-07 21:00:20

#### LeetCode_Easy心得：7. Reverse Integer（C语言）

2017-07-20 22:59:11

#### [leetcode 7] Reverse Integer(整数反转) c函数实现

2017-03-22 18:58:22

#### 7. Reverse Integer 反转int

2016-05-06 09:48:57

#### 7. Reverse Integer [easy] (Python)

2016-07-26 21:50:37

#### Leetcode 7 Reverse Integer 反转数字

2015-04-20 10:28:58

#### 7. Reverse Integer

2018-04-02 19:33:57

#### 7.Reverse Integer题目和答案详解

2017-11-23 11:08:11

#### LeetCode 7. Reverse Integer（反转整数）

2016-05-19 03:54:03