Skip to content

Commit b969f20

Browse files
authored
feat: add php solution to lc problem: No.0977 (#983)
1 parent 27cef69 commit b969f20

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

solution/0900-0999/0977.Squares of a Sorted Array/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,35 @@ impl Solution {
221221
}
222222
```
223223

224+
### **PHP**
225+
226+
```php
227+
class Solution {
228+
/**
229+
* @param Integer[] $nums
230+
* @return Integer[]
231+
*/
232+
function sortedSquares($nums) {
233+
$i = 0;
234+
$j = $k = count($nums) - 1;
235+
$rs = array_fill(0, count($nums), -1);
236+
while ($i <= $j) {
237+
$max1 = $nums[$i] * $nums[$i];
238+
$max2 = $nums[$j] * $nums[$j];
239+
if ($max1 > $max2) {
240+
$rs[$k] = $max1;
241+
$i++;
242+
} else {
243+
$rs[$k] = $max2;
244+
$j--;
245+
}
246+
$k--;
247+
}
248+
return $rs;
249+
}
250+
}
251+
```
252+
224253
### **...**
225254

226255
```

solution/0900-0999/0977.Squares of a Sorted Array/README_EN.md

+29
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,35 @@ impl Solution {
169169
}
170170
```
171171

172+
### **PHP**
173+
174+
```php
175+
class Solution {
176+
/**
177+
* @param Integer[] $nums
178+
* @return Integer[]
179+
*/
180+
function sortedSquares($nums) {
181+
$i = 0;
182+
$j = $k = count($nums) - 1;
183+
$rs = array_fill(0, count($nums), -1);
184+
while ($i <= $j) {
185+
$max1 = $nums[$i] * $nums[$i];
186+
$max2 = $nums[$j] * $nums[$j];
187+
if ($max1 > $max2) {
188+
$rs[$k] = $max1;
189+
$i++;
190+
} else {
191+
$rs[$k] = $max2;
192+
$j--;
193+
}
194+
$k--;
195+
}
196+
return $rs;
197+
}
198+
}
199+
```
200+
172201
### **...**
173202

174203
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
/**
3+
* @param Integer[] $nums
4+
* @return Integer[]
5+
*/
6+
function sortedSquares($nums) {
7+
$i = 0;
8+
$j = $k = count($nums) - 1;
9+
$rs = array_fill(0, count($nums), -1);
10+
while ($i <= $j) {
11+
$max1 = $nums[$i] * $nums[$i];
12+
$max2 = $nums[$j] * $nums[$j];
13+
if ($max1 > $max2) {
14+
$rs[$k] = $max1;
15+
$i++;
16+
} else {
17+
$rs[$k] = $max2;
18+
$j--;
19+
}
20+
$k--;
21+
}
22+
return $rs;
23+
}
24+
}

0 commit comments

Comments
 (0)