Created
August 21, 2020 04:34
-
-
Save AbhiAgarwal192/b2de192f74df1734dbd0e5226e037cf7 to your computer and use it in GitHub Desktop.
Given an array nums and a value val, remove all instances of that value in-place and return the new length.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int RemoveElement(int[] nums, int val) { | |
int len = nums.Length; | |
int i = 0; | |
int j = 0; | |
while(i<len){ | |
while(i<len && nums[i] == val){ | |
i++; | |
} | |
if(i<len){ | |
nums[j] = nums[i]; | |
j++; | |
} | |
i++; | |
} | |
return j; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment