Problem
Given a base a and an exponent b. Your task is to find ab. The value could be large enough. So, calculate ab % 1000000007.
Example One
{
"a": 2,
"b": 10
}
Output:
1024
Solution
function power(base, exponent) {
if (exponent === 1) {
return base;
} else {
return base * power(base ,exponent-1);
}
}
Time and Space Complexity
Time: O(b).
Auxiliary space: O(1).
Total space: O(1).