*Pow(x, n)

mac2022-06-30  81

Implement pow(x, n).

public class Solution { public double myPow(double x, int n) { if(n == 0) return 1; if(n<0){ n = -n; x = 1/x; } return (n%2 == 0) ? myPow(x*x, n/2) : x*myPow(x*x, n/2); } }

 

 

https://leetcode.com/discuss/17005/short-and-easy-to-understand-solution

 

转载于:https://www.cnblogs.com/hygeia/p/5090544.html

最新回复(0)