Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ed7e252

Browse files
feat(977): 新增java版本
1 parent f1b2eda commit ed7e252

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,9 +96,27 @@ public:
9696

9797
## 其他语言版本
9898

99-
10099
Java:
101100

101+
```java
102+
class Solution {
103+
public int[] sortedSquares(int[] nums) {
104+
int l = 0;
105+
int r = nums.length - 1;
106+
int[] res = new int[nums.length];
107+
int j = nums.length - 1;
108+
while(l <= r){
109+
if(nums[l] * nums[l] > nums[r] * nums[r]){
110+
res[j--] = nums[l] * nums[l++];
111+
}else{
112+
res[j--] = nums[r] * nums[r--];
113+
}
114+
}
115+
return res;
116+
}
117+
}
118+
```
119+
102120
Python:
103121
```Python
104122
class Solution:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /