/**
* @param {number} x
* @return {number}
*/
var reverse = function(x) {
var isNeg = false;
var str = "";
if (x < 0) {
x = Math.abs(x);
str += "-";
}
while (x > 0) {
str += x % 10;
x = parseInt( x / 10);
}
if (parseInt(str) > Math.pow(2, 31) - 1 || parseInt(str) < - Math.pow(2, 31)) {
return 0;
}
return str;
};
No comments:
Post a Comment