File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
solution/0200-0299/0238.Product of Array Except Self Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,30 @@ public class Solution {
229
229
}
230
230
```
231
231
232
+ ### ** PHP**
233
+
234
+ ``` php
235
+ class Solution {
236
+ /**
237
+ * @param Integer[] $nums
238
+ * @return Integer[]
239
+ */
240
+ function productExceptSelf($nums) {
241
+ $n = count($nums);
242
+ $ans = [];
243
+ for ($i = 0, $left = 1; $i < $n; ++$i) {
244
+ $ans[$i] = $left;
245
+ $left *= $nums[$i];
246
+ }
247
+ for ($i = $n - 1, $right = 1; $i >= 0; --$i) {
248
+ $ans[$i] *= $right;
249
+ $right *= $nums[$i];
250
+ }
251
+ return $ans;
252
+ }
253
+ }
254
+ ```
255
+
232
256
### ** ...**
233
257
234
258
```
Original file line number Diff line number Diff line change @@ -211,6 +211,30 @@ public class Solution {
211
211
}
212
212
```
213
213
214
+ ### ** PHP**
215
+
216
+ ``` php
217
+ class Solution {
218
+ /**
219
+ * @param Integer[] $nums
220
+ * @return Integer[]
221
+ */
222
+ function productExceptSelf($nums) {
223
+ $n = count($nums);
224
+ $ans = [];
225
+ for ($i = 0, $left = 1; $i < $n; ++$i) {
226
+ $ans[$i] = $left;
227
+ $left *= $nums[$i];
228
+ }
229
+ for ($i = $n - 1, $right = 1; $i >= 0; --$i) {
230
+ $ans[$i] *= $right;
231
+ $right *= $nums[$i];
232
+ }
233
+ return $ans;
234
+ }
235
+ }
236
+ ```
237
+
214
238
### ** ...**
215
239
216
240
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param Integer[] $nums
4
+ * @return Integer[]
5
+ */
6
+ function productExceptSelf ($nums ) {
7
+ $n = count ($nums );
8
+ $ans = [];
9
+ for ($i = 0 , $left = 1 ; $i < $n ; ++ $i ) {
10
+ $ans [$i ] = $left ;
11
+ $left *= $nums [$i ];
12
+ }
13
+ for ($i = $n - 1 , $right = 1 ; $i >= 0 ; -- $i ) {
14
+ $ans [$i ] *= $right ;
15
+ $right *= $nums [$i ];
16
+ }
17
+ return $ans ;
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments