leetcode : Pow(x, n)
runtime 0 ms, beats 100% of cpp submissions
O(log(n)) solution with explanation
tags: recursion, math
๐ link
๐ description
็ตฆๅฎๆธๅญ x ่ๆฌกๆธ n ๏ผๆฑ x^n ใ
ex. Input: x = 2.00000, n = 10 Output: 1024.00000
๐ง solution
ๅฟซ้ๅช + ่จๆถ็ตๆ๏ผๅฏไปฅๆๆ้่ค้ๅบฆๅฃๅฐ O(log(n)) ๏ผๆธๅฐ่จ็ฎ้่ค็็ๆ ใ
โณ time complexity
ๅฟซ้ๅชๆ้่ค้ๅบฆ O(log(n))
็ธฝๆ้่ค้ๅบฆ O(log(n))
๐ code
1 | class Solution { |