I am aware that there are three ways transform and conquer can be used to simplify a problem. I'm trying to simplify the code of this one to become more efficient. The thing is, it's already in log n runtime. I was wondering how I could possibly simplify this solution further? It's a recursive divide-and-conquer method in Java for a power algorithm where base = a and n= the exponential power. So basically x^n or A^n. I'm compiling it into codingbat which is why it's structured the way it is(codingbat has certain limitations). Any suggestions?
public int powerN(int base, int n) {
if (n==1)
return base;
else if (n==2)
return base*base;
else if (n%2==0)
return powerN(base*base, n/2);
else if (n%2==1)
return powerN(base, n-1)* base;
else
return 1;
}