Skip to content

Commit ca2e8aa

Browse files
Merge pull request #380 from KailokFeng/master
feat(977): 新增java版本
2 parents f659c18 + 1396008 commit ca2e8aa

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

problems/0977.有序数组的平方.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public:
9696

9797
## 其他语言版本
9898

99-
10099
Java:
101100
```Java
102101
class Solution {
@@ -119,6 +118,25 @@ class Solution {
119118
}
120119
```
121120

121+
```java
122+
class Solution {
123+
public int[] sortedSquares(int[] nums) {
124+
int l = 0;
125+
int r = nums.length - 1;
126+
int[] res = new int[nums.length];
127+
int j = nums.length - 1;
128+
while(l <= r){
129+
if(nums[l] * nums[l] > nums[r] * nums[r]){
130+
res[j--] = nums[l] * nums[l++];
131+
}else{
132+
res[j--] = nums[r] * nums[r--];
133+
}
134+
}
135+
return res;
136+
}
137+
}
138+
```
139+
122140
Python:
123141
```Python
124142
class Solution:

0 commit comments

Comments
 (0)