Question d’entretien chez LinkedIn

Implement java's pow function

Réponses aux questions d'entretien

Utilisateur anonyme

25 févr. 2013

Fast exponentiation: (I think this runs in order of O(log n), not sure though) static double fast_pow (double val, double n){ if (n==0) return 1; int x = fast_pow (val, n/2); x = x*x; if (n%2) x = x*val; return x; }

1

Utilisateur anonyme

29 nov. 2017

double myPow(double x, int n) { if(n==0) return 1; else { if(n%2==0) return myPow(x*x, n/2); else return x*myPow(x*x, n/2); }

Utilisateur anonyme

15 févr. 2013

static double pow(double val, double n) { double res = 1; for(int i = 0; i < n; i++) { result *= val; } return val; }

2