首页 > 代码库 > LeetCode:Pow(x, n)

LeetCode:Pow(x, n)

题目描述:

Implement pow(xn).


代码:

double solution::pow(double x,int n)
{
	if(n == 0)
		return 1;
	if(n == 1)
		return x;
	if(n < 0)
	{
		n = n * -1;
		x = 1 / x;
	}
	return n%2==0?pow(x*x,n/2):x*pow(x*x,n/2);
}


LeetCode:Pow(x, n)