Skip to content

Commit 187941b

Browse files
authored
Merge pull request #1967 from alexprudhomme/0027-remove-element.cs
Create: 0027-remove-element.cs
2 parents bc536cc + 67c2928 commit 187941b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

csharp/0027-remove-element.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Solution {
2+
public int RemoveElement(int[] nums, int val) {
3+
if (nums == null || nums.Length == 0)
4+
return 0;
5+
6+
int i = 0;
7+
8+
for (int j = 0; j < nums.Length; j++)
9+
{
10+
while (j < nums.Length && nums[j] == val)
11+
j++;
12+
13+
if (j < nums.Length)
14+
nums[i++] = nums[j];
15+
}
16+
17+
return i;
18+
}
19+
}

0 commit comments

Comments
 (0)