【LeetCode 0050】 pow

问题描述

https://leetcode.com/problems/powx-n/

代码

func myPow(x float64, n int) float64 {
    if (n == 0) {
        return 1.0
    }
    var half float64 = myPow(x,n/2)
    if (n % 2 == 0) {
        return half * half
    }
    if (n > 0) {
        return half * half * x
    }else {
        return half * half / x
    }
}

links

social