diff --git a/problems/0027.移除元素.md b/problems/0027.移除元素.md index 03c58b43..9d687cfb 100644 --- a/problems/0027.移除元素.md +++ b/problems/0027.移除元素.md @@ -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; + } +} +``` + -----------------------
diff --git a/problems/0977.有序数组的平方.md b/problems/0977.有序数组的平方.md index 4052c570..458107dd 100644 --- a/problems/0977.有序数组的平方.md +++ b/problems/0977.有序数组的平方.md @@ -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; + } +} +``` -----------------------