mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Merge pull request #1424 from Cwlrin/master
添加(0027.移除元素.md、0977.有序数组的平方.md):增加 C# 版本
This commit is contained in:
@ -339,7 +339,6 @@ int removeElement(int* nums, int numsSize, int val){
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Kotlin:
|
||||
```kotlin
|
||||
fun removeElement(nums: IntArray, `val`: Int): Int {
|
||||
@ -351,7 +350,6 @@ fun removeElement(nums: IntArray, `val`: Int): Int {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Scala:
|
||||
```scala
|
||||
object Solution {
|
||||
@ -368,5 +366,20 @@ object Solution {
|
||||
}
|
||||
```
|
||||
|
||||
C#:
|
||||
```csharp
|
||||
public class Solution {
|
||||
public int RemoveElement(int[] nums, int val) {
|
||||
int slow = 0;
|
||||
for (int fast = 0; fast < nums.Length; fast++) {
|
||||
if (val != nums[fast]) {
|
||||
nums[slow++] = nums[fast];
|
||||
}
|
||||
}
|
||||
return slow;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
@ -420,6 +420,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