mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
feat(977): 新增java版本
This commit is contained in:
@ -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:
|
||||
|
Reference in New Issue
Block a user