We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9635b5e + 8713220 commit cfcea5dCopy full SHA for cfcea5d
LeetCode Questions/C++/1. Problems/reverseInteger.cpp
@@ -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
+};
LeetCode Questions/C++/2. Accepted Screenshots/reverseInteger.png
83.4 KB
0 commit comments