Created
September 4, 2017 23:32
-
-
Save codediodeio/617184def4d42dadf602e6cd4a5b2201 to your computer and use it in GitHub Desktop.
Reverse integer and determine overflow in JavaScript - LeetCode solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} x | |
* @return {number} | |
*/ | |
var reverse = function(x) { | |
let a = x.toString().split('') | |
let num; | |
if(a[0] == '-') { | |
let c = a.shift() | |
num = parseInt(c +a.reverse().join('')) | |
} else { | |
num = parseInt(a.reverse().join('')) | |
} | |
if(Math.abs(num) > Math.pow(2, 31)) { | |
num = 0; | |
} | |
return num | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var reverse = function(x) {
var myInt = Math.abs(x).toString().split('').reverse().join('');
};
after submission my code status shows wrong answer on leetcode what is wrong with code please help me!