File tree 3 files changed +82
-0
lines changed
solution/0900-0999/0977.Squares of a Sorted Array
3 files changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -221,6 +221,35 @@ impl Solution {
221
221
}
222
222
```
223
223
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
+
224
253
### ** ...**
225
254
226
255
```
Original file line number Diff line number Diff line change @@ -169,6 +169,35 @@ impl Solution {
169
169
}
170
170
```
171
171
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
+
172
201
### ** ...**
173
202
174
203
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments