标签:
题目链接:https://leetcode.com/problems/powx-n/
题目:
Implement pow(x, n).
思路:
easy。上课例题= =
算法:
public double myPow(double x, int n) { if(n<0) return 1.0/(myPow2(x,-n)); else return myPow2(x,n); } public double myPow2(double x,int n){ if(n==0) return 1; double r= myPow2(x,n/2); if(n%2==0){ return r*r; }else{ return r*r*x; } }
标签:
原文地址:http://blog.csdn.net/yeqiuzs/article/details/51493589