Skip to content

Commit cf69af0

Browse files
authored
Merge branch 'crazycodigo:main' into amajaying-changed
2 parents 8c439a4 + cfcea5d commit cf69af0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
// taking x as input
4+
5+
int reverse(int x) {
6+
// initializing a reverse integer
7+
int rev = 0;
8+
// taking remainder and dividing number by 10 through looping
9+
10+
while (x != 0) {
11+
int pop = x % 10;
12+
x /= 10;
13+
if (rev > INT_MAX/10 || (rev == INT_MAX / 10 && pop > 7)) return 0;
14+
if (rev < INT_MIN/10 || (rev == INT_MIN / 10 && pop < -8)) return 0;
15+
rev = rev * 10 + pop;
16+
}
17+
return rev;
18+
}
19+
};
Loading

0 commit comments

Comments
 (0)