We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 878cd9f commit 0ba640fCopy full SHA for 0ba640f
Array/Array.Lib/RemoveElementSln.cs
@@ -0,0 +1,25 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+
6
+namespace Array.Lib
7
+{
8
+ public class RemoveElementSln
9
+ {
10
+ public int RemoveElement(int[] nums, int val)
11
12
+ int i = 0; //指向不等于元素val
13
+ for (int j = 0; j < nums.Length; j++)
14
15
+ while (j < nums.Length && nums[j] == val)
16
+ j++;
17
+ if (i < j && j < nums.Length)
18
+ nums[i] = nums[j];
19
+ if (j < nums.Length)
20
+ i++;
21
+ }
22
+ return i;
23
24
25
+}
0 commit comments