Skip to content

Commit

Permalink
Create: 0027-remove-element.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprudhomme committed Jan 8, 2023
1 parent fa2d4c3 commit 67c2928
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions csharp/0027-remove-element.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Solution {
public int RemoveElement(int[] nums, int val) {
if (nums == null || nums.Length == 0)
return 0;

int i = 0;

for (int j = 0; j < nums.Length; j++)
{
while (j < nums.Length && nums[j] == val)
j++;

if (j < nums.Length)
nums[i++] = nums[j];
}

return i;
}
}

0 comments on commit 67c2928

Please sign in to comment.