mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加(0977.有序数组的平方.md):增加 C# 版本
This commit is contained in:
@ -394,6 +394,24 @@ object Solution {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
C#:
|
||||
```csharp
|
||||
public class Solution {
|
||||
public int[] SortedSquares(int[] nums) {
|
||||
int k = nums.Length - 1;
|
||||
int[] result = new int[nums.Length];
|
||||
for (int i = 0, j = nums.Length - 1;i <= j;){
|
||||
if (nums[i] * nums[i] < nums[j] * nums[j]) {
|
||||
result[k--] = nums[j] * nums[j];
|
||||
j--;
|
||||
} else {
|
||||
result[k--] = nums[i] * nums[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
```
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
Reference in New Issue
Block a user