Conditions | 4 |
Paths | 5 |
Total Lines | 17 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
31 | public static function productExceptSelf2(array $nums): array |
||
32 | { |
||
33 | if (empty($nums)) { |
||
34 | return []; |
||
35 | } |
||
36 | $n = count($nums); |
||
37 | $ans = array_fill(0, $n, 0); |
||
38 | for ($i = 0, $tmp = 1; $i < $n; $i++) { |
||
39 | $ans[$i] = $tmp; |
||
40 | $tmp *= $nums[$i]; |
||
41 | } |
||
42 | for ($i = $n - 1, $tmp = 1; $i >= 0; $i--) { |
||
43 | $ans[$i] *= $tmp; |
||
44 | $tmp *= $nums[$i]; |
||
45 | } |
||
46 | |||
47 | return $ans; |
||
48 | } |
||
50 |