Created
July 29, 2021 02:44
-
-
Save TechWithTy/105adc5549c6fdf4e870c1e022c1f13e to your computer and use it in GitHub Desktop.
7. Reverse Integer
This file contains 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 = (x) => { | |
if (x < 0) { | |
return -1 * reverse(-x) | |
} | |
const solution = (x + "").split('').reverse().join(''); | |
return (solution > 2 ** 31 - 1) ? 0 : solution; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
made public