Skip to content

Commit b44378d

Browse files
authored
Merge pull request #1 from imajinyun/analysis-7aJd2Z
Apply fixes from StyleCI
2 parents cdfa6b7 + 79fd02c commit b44378d

File tree

147 files changed

+267
-271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+267
-271
lines changed

src/leetcode/AddToArrayFormOfInteger.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ public static function addToArrayForm(array $nums, int $k): array
1414
[$ans, $n] = [[], count($nums)];
1515
for ($i = $n - 1; $i >= 0; $i--) {
1616
$sum = $nums[$i] + $k % 10;
17-
$k = (int)($k / 10);
17+
$k = (int) ($k / 10);
1818
if ($sum >= 10) {
1919
$k++;
2020
$sum -= 10;
2121
}
22-
$ans[] = (int)$sum;
22+
$ans[] = (int) $sum;
2323
}
24-
for (; $k > 0; $k = (int)($k /= 10)) {
24+
for (; $k > 0; $k = (int) ($k /= 10)) {
2525
$ans[] = $k % 10;
2626
}
2727

@@ -36,11 +36,11 @@ public static function addToArrayForm2(array $nums, int $k): array
3636
$n = count($nums);
3737
for ($i = $n - 1; $i >= 0; $i--) {
3838
$ans[] = ($nums[$i] + $k) % 10;
39-
$k = (int)(($nums[$i] + $k) / 10);
39+
$k = (int) (($nums[$i] + $k) / 10);
4040
}
4141
while ($k > 0) {
4242
$ans[] = $k % 10;
43-
$k = (int)($k / 10);
43+
$k = (int) ($k / 10);
4444
}
4545

4646
return array_reverse($ans);
@@ -54,7 +54,7 @@ public static function addToArrayForm3(array $nums, int $k): array
5454
$n = count($nums);
5555
for ($i = $n - 1; $i >= 0 || $k > 0; $i--) {
5656
$ans[] = ($i >= 0 ? $nums[$i] + $k : $k) % 10;
57-
$k = (int)(($i >= 0 ? $nums[$i] + $k : $k) / 10);
57+
$k = (int) (($i >= 0 ? $nums[$i] + $k : $k) / 10);
5858
}
5959

6060
return array_reverse($ans);

src/leetcode/AndroidUnlockPatterns.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ private static function dfs(
5959
int $ans
6060
) {
6161
if ($len >= $m) {
62-
++$ans;
62+
$ans++;
6363
}
64-
++$len;
64+
$len++;
6565
if ($len > $n) {
6666
return $ans;
6767
}
6868
$visited[$curr] = true;
6969
for ($next = 1; $next < 10; $next++) {
7070
$jump = $jumps[$curr][$next];
71-
if (! $visited[$next] && ($jump === 0 || $visited[$jump])) {
71+
if (!$visited[$next] && ($jump === 0 || $visited[$jump])) {
7272
$ans = self::dfs($next, $len, $m, $n, $jumps, $visited, $ans);
7373
}
7474
}
@@ -90,7 +90,7 @@ private static function dfs2(
9090
$visited[$curr] = true;
9191
for ($next = 1; $next < 10; $next++) {
9292
$jump = $jumps[$curr][$next];
93-
if (! $visited[$next] && ($jump === 0 || $visited[$jump])) {
93+
if (!$visited[$next] && ($jump === 0 || $visited[$jump])) {
9494
$ans += self::dfs2($next, $jumps, $visited, $remain - 1);
9595
}
9696
}

src/leetcode/BestTimeToBuyAndSellStockII.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function maxProfit3(array $prices): int
4747
return 0;
4848
}
4949
$ans = [];
50-
for ($i = $n - 2; $i >= 0; --$i) {
50+
for ($i = $n - 2; $i >= 0; $i--) {
5151
$ans[] = max($prices[$i + 1] - $prices[$i], 0);
5252
}
5353

@@ -61,7 +61,7 @@ public static function maxProfit4(array $prices): int
6161
return 0;
6262
}
6363
$ans = 0;
64-
for ($i = 1; $i < $n; ++$i) {
64+
for ($i = 1; $i < $n; $i++) {
6565
$ans += max(0, $prices[$i] - $prices[$i - 1]);
6666
}
6767

src/leetcode/BestTimeToBuyAndSellStockIII.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static function maxProfit(array $prices): int
1414
}
1515
$dp = array_fill(0, $n, array_fill(0, $k, [0, 0, 0]));
1616
foreach ($prices as $i => $price) {
17-
for ($j = 1; $j < $k; ++$j) {
17+
for ($j = 1; $j < $k; $j++) {
1818
if ($i - 1 < 0) {
1919
$dp[$i][$j][0] = 0;
2020
$dp[$i][$j][1] = -$price;
@@ -53,17 +53,17 @@ public static function maxProfit3(array $prices): int
5353
}
5454
[$x, $y] = [array_pad([], $n, 0), array_pad([], $n, 0)];
5555

56-
for ($i = 1, $min = $prices[0]; $i < $n; ++$i) {
56+
for ($i = 1, $min = $prices[0]; $i < $n; $i++) {
5757
$min = min($min, $prices[$i]);
5858
$x[$i] = max($x[$i - 1], $prices[$i] - $min);
5959
}
6060

61-
for ($i = $n - 2, $max = $prices[$n - 1]; $i > 0; --$i) {
61+
for ($i = $n - 2, $max = $prices[$n - 1]; $i > 0; $i--) {
6262
$max = max($max, $prices[$i]);
6363
$y[$i] = max($y[$i + 1], $max - $prices[$i]);
6464
}
6565

66-
for ($i = 0; $i < $n; ++$i) {
66+
for ($i = 0; $i < $n; $i++) {
6767
$ans = max($ans, $x[$i] + $y[$i]);
6868
}
6969

src/leetcode/BestTimeToBuyAndSellStockIV.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function maxProfit(int $k, array $prices)
2828

2929
$dp = array_fill(0, $n, array_fill(0, $n, [0, 0, 0]));
3030
foreach ($prices as $i => $price) {
31-
for ($j = $k; $j > 0; --$j) {
31+
for ($j = $k; $j > 0; $j--) {
3232
if ($i - 1 < 0) {
3333
$dp[$i][$j][0] = 0;
3434
$dp[$i][$j][1] = -$price;
@@ -50,7 +50,7 @@ public static function maxProfit2(int $k, array $prices): int
5050
}
5151
$helper = static function () use ($prices) {
5252
[$n, $maxProfit] = [count($prices), 0];
53-
for ($i = 1; $i < $n; ++$i) {
53+
for ($i = 1; $i < $n; $i++) {
5454
if ($prices[$i] > $prices[$i - 1]) {
5555
$maxProfit += max(0, $prices[$i] - $prices[$i - 1]);
5656
}

src/leetcode/ClimbingStairs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static function climbStairs(int $n): int
1616
}
1717

1818
$dp = [1 => 1, 2 => 2];
19-
for ($i = 3; $i <= $n; ++$i) {
19+
for ($i = 3; $i <= $n; $i++) {
2020
$dp[$i] = $dp[$i - 1] + $dp[$i - 2];
2121
}
2222

@@ -32,7 +32,7 @@ public static function climbStairs2(int $n): int
3232
return $n;
3333
}
3434
[$prev, $curr] = [1, 1];
35-
for ($i = 2; $i < $n + 1; ++$i) {
35+
for ($i = 2; $i < $n + 1; $i++) {
3636
$temp = $curr;
3737
$curr = $prev + $curr;
3838
$prev = $temp;

src/leetcode/CoinChange.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace leetcode;
66

7-
use SplFixedArray;
8-
97
class CoinChange
108
{
119
public static function coinChange(array $coins, int $amount): int
@@ -15,8 +13,8 @@ public static function coinChange(array $coins, int $amount): int
1513
return 0;
1614
}
1715
[$dp, $dp[0]] = [array_fill(0, $m, $m), 0];
18-
for ($i = 1; $i < $m; ++$i) {
19-
for ($j = 0; $j < $n; ++$j) {
16+
for ($i = 1; $i < $m; $i++) {
17+
for ($j = 0; $j < $n; $j++) {
2018
$coin = $coins[$j];
2119
if ($coin <= $i) {
2220
$dp[$i] = min($dp[$i], $dp[$i - $coin] + 1);
@@ -34,7 +32,7 @@ public static function coinChange2(array $coins, int $amount): int
3432
return 0;
3533
}
3634
[$dp, $max] = [array_fill(0, $m, 0), PHP_INT_MAX];
37-
for ($i = 1; $i < $m; ++$i) {
35+
for ($i = 1; $i < $m; $i++) {
3836
$dp[$i] = $max;
3937
foreach ($coins as $coin) {
4038
if ($coin <= $i && $dp[$i - $coin] !== $max) {

src/leetcode/CountNumbersWithUniqueDigits.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ private static function dfs(int $target, int $index, array &$visited): int
4747
}
4848
$count = 0;
4949
for ($i = $index ? 0 : 1; $i < 10; $i++) {
50-
if (! $visited[$i]) {
50+
if (!$visited[$i]) {
5151
$visited[$i] = true;
5252
$count += self::dfs($target, $index + 1, $visited);
5353
$visited[$i] = false;
5454
}
5555
}
5656

5757
return $count;
58-
5958
}
6059
}

src/leetcode/DecodeWays.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public static function numDecodings(string $s): int
1515

1616
$dp = array_fill(0, $n + 1, 0);
1717
[$dp[0], $dp[1]] = [1, 1];
18-
for ($i = 2; $i <= $n; ++$i) {
19-
[$p, $q] = [(int)$s[$i - 1], (int)$s[$i - 2]];
18+
for ($i = 2; $i <= $n; $i++) {
19+
[$p, $q] = [(int) $s[$i - 1], (int) $s[$i - 2]];
2020
$dp[$i] = $p === 0 ? 0 : $dp[$i - 1];
2121
if ($q === 1 || ($q === 2 && $p <= 6)) {
2222
$dp[$i] += $dp[$i - 2];
@@ -42,7 +42,7 @@ public static function numDecodings2(string $s): int
4242

4343
$dp = array_fill(0, $n + 1, 0);
4444
[$dp[0], $dp[1]] = [1, 1];
45-
for ($i = 2; $i <= $n; ++$i) {
45+
for ($i = 2; $i <= $n; $i++) {
4646
$p = $helper($s, $i - 1, $i);
4747
$q = $helper($s, $i - 2, $i);
4848
if ($p >= 1 && $p <= 9) {

src/leetcode/DegreeOfAnArray.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public static function findShortestSubArray(array $nums): int
1414
$cnt = $map = [];
1515
$res = $degree = 0;
1616
foreach ($nums as $k => $v) {
17-
if (! isset($map[$v])) {
17+
if (!isset($map[$v])) {
1818
$map[$v] = $k;
1919
}
20-
if (! isset($cnt[$v])) {
20+
if (!isset($cnt[$v])) {
2121
$cnt[$v] = 0;
2222
}
2323
$cnt[$v]++;

src/leetcode/DivisorGame.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public static function divisorGame2(int $n): bool
2424
$dp = array_fill(0, $n + 1, false);
2525
$dp[1] = false;
2626
$dp[2] = true;
27-
for ($i = 3; $i <= $n; ++$i) {
28-
for ($j = 1; $j < $i; ++$j) {
29-
if ($i % $j === 0 && ! $dp[$i - $j]) {
27+
for ($i = 3; $i <= $n; $i++) {
28+
for ($j = 1; $j < $i; $j++) {
29+
if ($i % $j === 0 && !$dp[$i - $j]) {
3030
$dp[$i] = true;
3131
break;
3232
}

src/leetcode/FairCandySwap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static function fairCandySwap(array $a, array $b): array
1212
return [];
1313
}
1414
[$aSum, $bSum] = [array_sum($a), array_sum($b)];
15-
$dif = (int)(($aSum - $bSum) / 2);
15+
$dif = (int) (($aSum - $bSum) / 2);
1616
for ($i = 0, $m = count($a); $i < $m; $i++) {
1717
for ($j = 0, $n = count($b); $j < $n; $j++) {
1818
if ($a[$i] - $b[$j] === $dif) {
@@ -29,9 +29,9 @@ public static function fairCandySwap2(array $a, array $b): array
2929
if (empty($a) || empty($b)) {
3030
return [];
3131
}
32-
[$map, $dif] = [[], (int)((array_sum($a) - array_sum($b)) / 2)];
32+
[$map, $dif] = [[], (int) ((array_sum($a) - array_sum($b)) / 2)];
3333
foreach ($a as $v) {
34-
if (! isset($map[$v])) {
34+
if (!isset($map[$v])) {
3535
$map[$v] = $v;
3636
}
3737
}

src/leetcode/FindPivotIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static function pivotIndex(array $nums): int
1111
if (empty($nums)) {
1212
return 0;
1313
}
14-
[$left, $right]= [0, array_sum($nums)];
14+
[$left, $right] = [0, array_sum($nums)];
1515
foreach ($nums as $key => $num) {
1616
$right -= $num;
1717
if ($left === $right) {

src/leetcode/GenerateParentheses.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private static function addParenthesis(array &$ans, int $left, int $right, strin
1818
{
1919
if ($left === 0 && $right === 0) {
2020
$ans[] = $s;
21+
2122
return;
2223
}
2324

src/leetcode/HouseRobber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function rob3(array $nums): int
4949
$dp = array_fill(0, $n, 0);
5050
$dp[0] = $nums[0];
5151
$dp[1] = max($nums[0], $nums[1]);
52-
for ($i = 2; $i < $n; ++$i) {
52+
for ($i = 2; $i < $n; $i++) {
5353
$dp[$i] = max($dp[$i - 1], $dp[$i - 2] + $nums[$i]);
5454
}
5555

src/leetcode/ImageSmoother.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function imageSmoother(array $arr): array
2525
}
2626
}
2727
if ($cnt > 0) {
28-
$ans[$i][$j] = (int)floor($ans[$i][$j] / $cnt);
28+
$ans[$i][$j] = (int) floor($ans[$i][$j] / $cnt);
2929
}
3030
}
3131
}
@@ -74,7 +74,7 @@ public static function imageSmoother2(array $arr): array
7474
if (isset($arr[$i + 1][$j + 1])) {
7575
$tmp[] = $arr[$i + 1][$j + 1];
7676
}
77-
$tmp = (int)floor(array_sum($tmp) / count($tmp));
77+
$tmp = (int) floor(array_sum($tmp) / count($tmp));
7878
$res[$i][$j] = $tmp;
7979
}
8080
}

src/leetcode/ImplementQueueUsingStacks.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ public function push(int $value): void
1515
if (empty($this->stack)) {
1616
$this->front = $value;
1717
}
18-
while (! empty($this->stack)) {
18+
while (!empty($this->stack)) {
1919
$this->cache[] = array_shift($this->stack);
2020
}
2121
$this->cache[] = $value;
22-
while (! empty($this->cache)) {
22+
while (!empty($this->cache)) {
2323
$this->stack[] = array_shift($this->cache);
2424
}
2525
}
2626

2727
public function pop(): ?int
2828
{
2929
$value = array_shift($this->stack);
30-
if (! empty($this->stack)) {
30+
if (!empty($this->stack)) {
3131
$this->front = current($this->stack);
3232
}
3333

src/leetcode/ImplementQueueUsingStacks2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function pop(): ?int
2424
public function peek(): ?int
2525
{
2626
if (empty($this->stack)) {
27-
while (! empty($this->cache)) {
27+
while (!empty($this->cache)) {
2828
$this->stack[] = array_shift($this->cache);
2929
}
3030
}

src/leetcode/ImplementTriePrefixTree.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class ImplementTriePrefixTree
1010
{
11-
/** @var \leetcode\util\TrieNode $root */
11+
/** @var \leetcode\util\TrieNode */
1212
private $root;
1313

1414
public function __construct()
@@ -22,20 +22,20 @@ public function insert(string $word): void
2222
$node = $this->root;
2323
for ($i = 0, $n = strlen($word); $i < $n; $i++) {
2424
$value = $word[$i];
25-
if (! isset($node->children[$value])) {
25+
if (!isset($node->children[$value])) {
2626
$node->children[$value] = new TrieNode($value);
2727
}
2828
$node = $node->children[$value];
2929
}
3030
$node->isWord = true;
3131
}
3232

33-
public function search (string $prefix): bool
33+
public function search(string $prefix): bool
3434
{
3535
$node = $this->root;
3636
for ($i = 0, $n = strlen($prefix); $i < $n; $i++) {
3737
$value = $prefix[$i];
38-
if (! isset($node->children[$value])) {
38+
if (!isset($node->children[$value])) {
3939
return false;
4040
}
4141
$node = $node->children[$value];
@@ -46,10 +46,10 @@ public function search (string $prefix): bool
4646

4747
public function startsWith(string $prefix): bool
4848
{
49-
$node= $this->root;
49+
$node = $this->root;
5050
for ($i = 0, $n = strlen($prefix); $i < $n; $i++) {
5151
$value = $prefix[$i];
52-
if (! isset($node->children[$value])) {
52+
if (!isset($node->children[$value])) {
5353
return false;
5454
}
5555
$node = $node->children[$value];

0 commit comments

Comments
 (0)