Skip to content

Commit 8399348

Browse files
committed
feat: add cpp solution to leetcode problem: No.0007. Reverse Integer
1 parent f0bb274 commit 8399348

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

solution/0000-0099/0007.Reverse Integer/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ class Solution {
8888
}
8989
```
9090

91+
### **C++**
92+
93+
```cpp
94+
class Solution {
95+
public:
96+
int reverse(int x) {
97+
long long ans = 0;
98+
while (x) {
99+
ans = ans * 10 + x % 10;
100+
x /= 10;
101+
}
102+
return ans < INT_MIN || ans > INT_MAX ? 0 : ans;
103+
}
104+
};
105+
```
106+
91107
### **...**
92108
93109
```

solution/0000-0099/0007.Reverse Integer/README_EN.md

+16
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ class Solution {
5959
}
6060
```
6161

62+
### **C++**
63+
64+
```cpp
65+
class Solution {
66+
public:
67+
int reverse(int x) {
68+
long long ans = 0;
69+
while (x) {
70+
ans = ans * 10 + x % 10;
71+
x /= 10;
72+
}
73+
return ans < INT_MIN || ans > INT_MAX ? 0 : ans;
74+
}
75+
};
76+
```
77+
6278
### **...**
6379
6480
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public:
3+
int reverse(int x) {
4+
long long ans = 0;
5+
while (x) {
6+
ans = ans * 10 + x % 10;
7+
x /= 10;
8+
}
9+
return ans < INT_MIN || ans > INT_MAX ? 0 : ans;
10+
}
11+
};

0 commit comments

Comments
 (0)