diff --git a/problems/0977.有序数组的平方.md b/problems/0977.有序数组的平方.md index b5d392e6..d28a9427 100644 --- a/problems/0977.有序数组的平方.md +++ b/problems/0977.有序数组的平方.md @@ -96,9 +96,27 @@ public: ## 其他语言版本 - Java: +```java +class Solution { + public int[] sortedSquares(int[] nums) { + int l = 0; + int r = nums.length - 1; + int[] res = new int[nums.length]; + int j = nums.length - 1; + while(l <= r){ + if(nums[l] * nums[l] > nums[r] * nums[r]){ + res[j--] = nums[l] * nums[l++]; + }else{ + res[j--] = nums[r] * nums[r--]; + } + } + return res; + } +} +``` + Python: ```Python class Solution: