Math Fundamentals18 sections · 814 units
Open in Course

Problem - Power Function

LeetCode 50

Implement a function that computes xnx^n, where xx is a floating-point number and nn is an integer (possibly negative).

For example, pow(2.0,10)=1024.0pow(2.0, 10) = 1024.0 and pow(2.0,2)=0.25pow(2.0, -2) = 0.25.

Before reading on, think: how would you do this? A loop that multiplies nn times? That's one way. But can you do better?