7-reverse-integer

DevGod
Vtuber
class Solution { public int reverse(int x) { String str = Long.toString(Math.abs((long)x)); StringBuffer sbr = new StringBuffer(str); sbr.reverse(); str = sbr.toString(); if(x<0){str = "-"+str;}
long value = Long.parseLong(str); int value2 = (int)Long.parseLong(str); if(value != value2){ return 0; } return (int)value; }}
/** * @param {number} x * @return {number} */var reverse = function (x) { let sign = 1; if (x < 0) { sign = -1; x *= -1; } let myNum = 0; while (x > 0) { const digit = x % 10; if (x > 0) { x = Math.floor(x / 10); } myNum = myNum * 10 + digit; } if (myNum > Math.pow(2, 31)) { return 0; } return sign * myNum;};