Pow(x, n) Flashcards
1
Q
Pow(x, n)
A
a) n == 0 return 1
b) if n < 0 n = -n and x = 1/x
c) n%2 == 1 ? x * pow(x*x, n/2) : pow(x*x, n/2)
Medium > Pow(x, n) > Flashcards
Pow(x, n)
a) n == 0 return 1
b) if n < 0 n = -n and x = 1/x
c) n%2 == 1 ? x * pow(x*x, n/2) : pow(x*x, n/2)