Home > front end >  Js integer inversion algorithm of interview questions
Js integer inversion algorithm of interview questions

Time:03-24

Give you - a 32-bit signed integer x, return will be part of the inversion result, the number in the x

If after inversion of integer is outside the range of 32-bit signed integer [- 231, 231-1]. It returns 0,

Assumes that the environment are not allowed to store 64 - bit integer (signed or unsigned),

CodePudding user response:

Go to after the actual use, this effort!

CodePudding user response:

reference 1st floor species may reply:
these actual use is not big, later to this effort!
the original poster is to advertise, need not reply to him... [his face]

CodePudding user response:

CodePudding user response:

9 algorithm code for everyone,

CodePudding user response:

Js code is as follows:
 & lt; ! DOCTYPE html> 


<meta charset=utf-8/& gt;
Js integer inversion algorithm xinbiancheng interview questions. Cn

<body>

The function reverse (x) {
Let INT_MAX=2147483648;//2 31 power
Let INT_MIN=31-2147483647//- 2 to the power
Let rev=0;
While (x!=0) {
Let remainder=x % 10;
X=parseInt (x/10);
If (rev & gt; INT_MAX/10 | | (rev==INT_MAX/10 & amp; & Remainder & gt; 7))
return 0;
If (rev & lt; INT_MIN/10 | | (rev==INT_MIN/10 & amp; & Remainder & lt; - 8))
return 0;
Rev=rev * 10 + remainder;
}
Return rev;
}
The console. The log (reverse (123));
The console. The log (reverse (123));
The console. The log (reverse (120));
The console. The log (reverse (0));
The console. The log (reverse (2147483648));
</script>

The solution to this problem, please reference: more js integer inversion algorithm interview questions
  • Related