@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | [$m, $n] = [count($matrix), count($matrix[0])]; |
| 34 | 34 | [$low, $high] = [$matrix[0][0], $matrix[$m - 1][$n - 1]]; |
| 35 | - $helper = static function (array $matrix, int $target) { |
|
| 35 | + $helper = static function(array $matrix, int $target) { |
|
| 36 | 36 | $n = count($matrix); |
| 37 | 37 | [$cnt, $i, $j] = [0, $n - 1, 0]; |
| 38 | 38 | while ($i >= 0 && $j < $n) { |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | 49 | while ($low < $high) { |
| 50 | - $mid = (int)(($high - $low) / 2) + $low; |
|
| 50 | + $mid = (int) (($high - $low) / 2) + $low; |
|
| 51 | 51 | $cnt = $helper($matrix, $mid); |
| 52 | 52 | if ($cnt < $k) { |
| 53 | 53 | $low = $mid + 1; |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | array_push($stack, -$num); |
| 31 | 31 | break; |
| 32 | 32 | case '*': |
| 33 | - array_push($stack, (int)(array_pop($stack) * $num)); |
|
| 33 | + array_push($stack, (int) (array_pop($stack) * $num)); |
|
| 34 | 34 | break; |
| 35 | 35 | case '/': |
| 36 | - array_push($stack, (int)(array_pop($stack) / $num)); |
|
| 36 | + array_push($stack, (int) (array_pop($stack) / $num)); |
|
| 37 | 37 | break; |
| 38 | 38 | } |
| 39 | 39 | [$num, $operator] = [0, $char]; |
@@ -56,16 +56,16 @@ discard block |
||
| 56 | 56 | $char = $s[$i]; |
| 57 | 57 | if (is_numeric($char)) { |
| 58 | 58 | if ($operator === '+') { |
| 59 | - array_push($stack, (int)$char); |
|
| 59 | + array_push($stack, (int) $char); |
|
| 60 | 60 | } |
| 61 | 61 | if ($operator === '-') { |
| 62 | - array_push($stack, -(int)$char); |
|
| 62 | + array_push($stack, -(int) $char); |
|
| 63 | 63 | } |
| 64 | 64 | if ($operator === '*') { |
| 65 | - array_push($stack, array_pop($stack) * (int)$char); |
|
| 65 | + array_push($stack, array_pop($stack) * (int) $char); |
|
| 66 | 66 | } |
| 67 | 67 | if ($operator === '/') { |
| 68 | - array_push($stack, (int)(array_pop($stack) / $char)); |
|
| 68 | + array_push($stack, (int) (array_pop($stack) / $char)); |
|
| 69 | 69 | } |
| 70 | 70 | } else { |
| 71 | 71 | $operator = $char; |
@@ -22,9 +22,9 @@ discard block |
||
| 22 | 22 | $stack->push($stack->pop() * $stack->pop()); |
| 23 | 23 | } elseif ($token === '/') { |
| 24 | 24 | [$b, $a] = [$stack->pop(), $stack->pop()]; |
| 25 | - $stack->push((int)($a / $b)); |
|
| 25 | + $stack->push((int) ($a / $b)); |
|
| 26 | 26 | } else { |
| 27 | - $stack->push((int)$token); |
|
| 27 | + $stack->push((int) $token); |
|
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | $stack = []; |
| 40 | 40 | foreach ($tokens as $token) { |
| 41 | 41 | if (!in_array($token, ['+', '-', '*', '/'])) { |
| 42 | - array_push($stack, (int)$token); |
|
| 42 | + array_push($stack, (int) $token); |
|
| 43 | 43 | } else { |
| 44 | 44 | [$r, $l] = [array_pop($stack), array_pop($stack)]; |
| 45 | 45 | if ($token === '+') { |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | } elseif ($token === '*') { |
| 50 | 50 | array_push($stack, $l * $r); |
| 51 | 51 | } else { |
| 52 | - array_push($stack, (int)($l / $r)); |
|
| 52 | + array_push($stack, (int) ($l / $r)); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | } |
| 27 | 27 | [$left, $right] = [0, count($nums) - 1]; |
| 28 | 28 | while ($left < $right) { |
| 29 | - $mid = $left + (int)(($right - $left) / 2); |
|
| 29 | + $mid = $left + (int) (($right - $left) / 2); |
|
| 30 | 30 | if ($nums[$mid] < $nums[$mid + 1]) { |
| 31 | 31 | $left = $mid + 1; |
| 32 | 32 | } else { |
@@ -36,13 +36,13 @@ |
||
| 36 | 36 | } |
| 37 | 37 | [$low, $high] = [$nums[0], count($nums) - 1]; |
| 38 | 38 | while ($low < $high) { |
| 39 | - [$cnt, $mid] = [0, $low + (int)(($high - $low) / 2)]; |
|
| 39 | + [$cnt, $mid] = [0, $low + (int) (($high - $low) / 2)]; |
|
| 40 | 40 | foreach ($nums as $num) { |
| 41 | 41 | if ($num <= $mid) { |
| 42 | 42 | $cnt++; |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | - $cnt <= $mid ? ($low = $mid + 1) : ($high = $mid); |
|
| 45 | + $cnt <= $mid ? ($low = $mid + 1) : ($high = $mid); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | return $low; |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | - if ((int)$nums[0] === 0) { |
|
| 21 | + if ((int) $nums[0] === 0) { |
|
| 22 | 22 | return '0'; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - return (string)join('', $nums); |
|
| 25 | + return (string) join('', $nums); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public static function largestNumber2(array $nums): string |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | if (empty($nums)) { |
| 31 | 31 | return ''; |
| 32 | 32 | } |
| 33 | - usort($nums, static function ($a, $b) { |
|
| 33 | + usort($nums, static function($a, $b) { |
|
| 34 | 34 | return -(($a . $b) <=> ($b . $a)); |
| 35 | 35 | }); |
| 36 | - if ((int)$nums[0] === 0) { |
|
| 36 | + if ((int) $nums[0] === 0) { |
|
| 37 | 37 | return '0'; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - return (string)implode('', $nums); |
|
| 40 | + return (string) implode('', $nums); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | private static function compare(int $a, int $b): int |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | } |
| 14 | 14 | [$low, $high] = [1, $m]; |
| 15 | 15 | while ($low <= $high) { |
| 16 | - $mid = $low + (int)(($high - $low) / 2); |
|
| 16 | + $mid = $low + (int) (($high - $low) / 2); |
|
| 17 | 17 | if (self::isBadVersion($mid, $n)) { |
| 18 | 18 | $high = $mid - 1; |
| 19 | 19 | } else { |
@@ -12,9 +12,9 @@ |
||
| 12 | 12 | return 0; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - $z = (string)(decbin($x ^ $y)); |
|
| 15 | + $z = (string) (decbin($x ^ $y)); |
|
| 16 | 16 | |
| 17 | - return (int)(substr_count($z, '1')); |
|
| 17 | + return (int) (substr_count($z, '1')); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public static function hammingDistance2(int $x, int $y): int |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | $map[$s[$i]] = ($map[$s[$i]] ?? 0) + 1; |
| 34 | 34 | } |
| 35 | 35 | foreach ($map as $val) { |
| 36 | - $ans += (int)($val / 2) * 2; |
|
| 36 | + $ans += (int) ($val / 2) * 2; |
|
| 37 | 37 | if ($ans % 2 === 0 && $val % 2 === 1) { |
| 38 | 38 | $ans++; |
| 39 | 39 | } |