for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace leetcode;
class Pow
{
public static function myPow(float $x, int $n): float
if ($n === 0) {
return 1;
}
if ($n < 0) {
[$x, $n] = [1 / $x, -$n];
if ($n % 2 === 0) {
$ans = self::myPow($x * $x, $n / 2);
} else {
$ans = $x * self::myPow($x * $x, intdiv($n, 2));
return $ans;
public static function myPow2(float $x, int $n): float
$ans = 1;
while ($n) {
if ($n & 1) {
$ans *= $x;
$x *= $x;
$n >>= 1;
public static function myPow3(float $x, int $n): float
if ($n == 0) {
return 1 / self::myPow3($x, -$n);
$y = self::myPow3($x, (int)($n / 2));
return $n % 2 === 0 ? $y * $y : $y * $y * $x;