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.
1 parent caa0927 commit 3a67ad4Copy full SHA for 3a67ad4
solution/007.Reverse Integer/Solution.js
@@ -0,0 +1,15 @@
1
+const reverse1 = function(x){
2
+ let s = String(x);
3
+ let isNegative = false;
4
+ if(s[0] === '-'){
5
+ isNegative = true;
6
+ }
7
+ s = parseInt(s.split('').reverse().join(''));
8
+ return isNegative ? (s > Math.pow(2,31) ? 0 : -s) : (s > Math.pow(2,31) - 1 ? 0 : s);
9
+}
10
+
11
+const reverse = function(x){
12
+ let result = parseInt(x.toString().split('').reverse().join(''));
13
+ if(result > Math.pow(2,31) - 1 || -result < Math.pow(-2,31)) return 0;
14
+ return x > 0 ? result: -result;
15
0 commit comments