Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3da8b15

Browse files
authored
feat: add php solution to lc problem: No.0238 (#1189)
1 parent 0c7a735 commit 3da8b15

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

‎solution/0200-0299/0238.Product of Array Except Self/README.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,30 @@ public class Solution {
229229
}
230230
```
231231

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+
232256
### **...**
233257

234258
```

‎solution/0200-0299/0238.Product of Array Except Self/README_EN.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,30 @@ public class Solution {
211211
}
212212
```
213213

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+
214238
### **...**
215239

216240
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /