Skip to content

Commit 0655fbc

Browse files
author
cpppy
authored
Create 7_Reverse_Integer.cc
1 parent 5d587ef commit 0655fbc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

7_Reverse_Integer.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int reverse(int x) {
4+
int num=0;
5+
while(x!=0){
6+
if(abs(num) > INT_MAX/10 )return 0; //防止溢出
7+
num=num*10+(x%10);
8+
x=x/10;
9+
}
10+
return num;
11+
}
12+
};

0 commit comments

Comments
 (0)