public class Solution {
public double myPow(double x, int n) {
double o = 1;
for (int m = n; m != 0; m /= 2) {
if (m % 2 != 0)
o *= x;
x *= x;
}
return n > 0 ? o : 1 / o;
}
}
Java: compact, nonrecursive, naturally handles n=MIN_VALUE.

@blackler said in Java: compact, nonrecursive, naturally handles n=MIN_VALUE.:
double o = 1;
for (int m = n; m != 0; m /= 2) {
if (m % 2 != 0)
o *= x;
x *= x;
}
return n > 0 ? o : 1 / o;Could you please explain how it handles the overflow case?