整数反转

https://leetcode-cn.com/problems/reverse-integer/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* @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
}