Essa empresa é sua?
Write a power function power(a , b) returns a^b
Sigiloso
def power(a, b): return a**b
double pow(int a,int b) { if(b0) { if(b%2==1) res*=a; a*=a; b>>1; } return res }
long power(int a, int n) { if(n%2==0) return power(a,n/2)*power(a,n/2); else if (n%2==1&&n!=1) return power(a,n-1)*a; else //n==1 return a; }
def power(a,b): if b is 1: return a return a * (power(a, b--))
There are some conditions you are missing. What if b is <=0 ?
The conditions made by the Hulu rep was to assume b > 0. However there is a better way to do this problem.
int power (double a, int b) { for (int i = 1, i <= b, i++) { a *= a; } return a; }
Fique por dentro de todas as oportunidades e dicas internas seguindo as empresas de seus sonhos.
Comece a buscar vagas para receber atualizações e recomendações personalizadas.