```
double pow(double x, int n) {
if(n==0) return 1;
if(n==1) return x;
if(x==0) return x;
if(n<0) return pow(1/x, -n);
if(n%2) return x*pow(x*x, n/2);
else return pow(x*x, n/2);
}
```

Last executed input: 1.00000, -2147483648

However, my code below works! I just change one line! But, I think both are same!

```
class Solution {
public:
double pow(double x, int n) {
if(n==0) return 1;
if(n==1) return x;
if(x==0) return x;
if(n<0){
x = 1/x;
n = -n;
}
if(n%2) return x*pow(x*x, n/2);
else return pow(x*x, n/2);
}
}
```

;

I have no idea what the bug is in my first version. Thanks for your help!