整数反转 发表于 2021-04-14 https://leetcode-cn.com/problems/reverse-integer/123456789101112131415161718192021222324252627/** * @param {number} x * @return {number} */ var reverse = function(x) { if(x>0){ return reverseZ(x) } else{ x=0-x; return 0-reverseZ(x) } }; var reverseZ= function(x){ if(x>=Math.pow(2,31)){ return 0 } let y=[],i=1; while(x>=1){ y.push((parseInt(x%10))) x/=10 } let res=Number(y.join().replaceAll(",","")) if(res>Math.pow(2,31)) return 0 return res }