LeetCode 50. Pow(x, n)x的n的次方

    xiaoxiao2021-04-15  59

    Implement pow(xn).

    Subscribe to see which companies asked this question.

    public class Solution { public double myPow(double x, int n) { if(n==0) return 1; double mid = myPow(x,n/2); if(n%2==0) return mid*mid; else{ if(n>0) return mid*mid*x; else return mid*mid*(1/x); } } } 分治法,时间复杂度O(nlogn)

    转载请注明原文地址: https://ju.6miu.com/read-670857.html

    最新回复(0)