```
public double myPow(double x, int n) {
double res=0.0;
if(n==0)
return 1.0;
boolean flag=false;
if(n<0){
flag=true;
n=-n;
}
if(n%2==0){
res=myPow(x,n/2)*myPow(x,n/2);
}else{
res=myPow(x,n/2)*myPow(x,n/2)*x;
}
if(flag==true){
res=1.0/res;
}
return res;
}
```

Above is my code, however, I met the problem:Line 10: java.lang.StackOverflowError 8.88023 3

I tested it on 8.88023 3 and it's working. I want to know the following questions:

1.StackOverflowError does that means too much space?

2.my code is not good because I calculate myPow twice instead of creating double half = myPow(x, n/2) and just use it later?

- What's the time complexity of my code and the optimized code like others?

Thank you so much for teaching me and solving the problem for me!

Thanks