1. 题目说明
实现 pow(x, n) ,即计算 x 的 n 次幂函数。
2. 解题
<?phpclass Solution {/*** @param Float $x* @param Integer $n* @return Float*/public function myPow($x, $n) {if ($n < 0) {return 1 / $this->myPow($x, $n);}if ($n == 1) {return $x;}if ($n % 2) {return $x * $this->myPow($x, $n - 1);}return $this->myPow($x, $n / 2) * $this->myPow($x, $n / 2);}}$cls = new Solution();$r = $cls->myPow(3, 3);echo $r;
