diff --git a/csharp/0027-remove-element.cs b/csharp/0027-remove-element.cs new file mode 100644 index 000000000..ea70dc16d --- /dev/null +++ b/csharp/0027-remove-element.cs @@ -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; + } +} \ No newline at end of file