diff --git a/problems/0977.有序数组的平方.md b/problems/0977.有序数组的平方.md index f3e9cf38..d2e1f950 100644 --- a/problems/0977.有序数组的平方.md +++ b/problems/0977.有序数组的平方.md @@ -96,7 +96,6 @@ public: ## 其他语言版本 - Java: ```Java class Solution { @@ -119,6 +118,25 @@ class Solution { } ``` +```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: