Est-ce votre entreprise ?
Write a power function power(a , b) returns a^b
Utilisateur anonyme
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; }
Tenez-vous au courant des dernières opportunités et profitez de conseils d’initiés en suivant les entreprises de vos rêves.
Obtenez des recommandations et des mises à jour personnalisées en démarrant vos recherches.