We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d07f114 commit 0d38089Copy full SHA for 0d38089
1 file changed
算法与数据结构/leetcode/leetcode.md
@@ -3425,3 +3425,29 @@ class ParkingSystem {
3425
```
3426
3427
time: 16 beat:9
3428
+
3429
+## 977. 有序数组的平方
3430
3431
+<https://leetcode-cn.com/problems/squares-of-a-sorted-array/>
3432
3433
+```java
3434
+class Solution {
3435
+ public int[] sortedSquares(int[] nums) {
3436
+ for(int i=0;i<nums.length;i++){
3437
+ nums[i] = nums[i] * nums[i];
3438
+ }
3439
+ int p=0,q=nums.length - 1;
3440
+ int[] ret = new int[nums.length];
3441
+ for(int i = nums.length - 1; i>=0;i--){
3442
+ if (nums[p] > nums[q]){
3443
+ ret[i] = nums[p++];
3444
+ }else if (nums[p] <= nums[q]) {
3445
+ ret[i] = nums[q--];
3446
3447
3448
+ return ret;
3449
3450
+}
3451
+```
3452
3453
+time:1 beat:100
0 commit comments