Skip to content

Instantly share code, notes, and snippets.

@AnjaliManhas
Created May 6, 2020 12:55
Show Gist options
  • Save AnjaliManhas/43352bfd49350ca847712bbc5de9c378 to your computer and use it in GitHub Desktop.
Save AnjaliManhas/43352bfd49350ca847712bbc5de9c378 to your computer and use it in GitHub Desktop.
Remove Element- LeetCode: Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond the new l…
class Solution {
public int removeElement(int[] nums, int val) {
int i, count= 0;
for(i=0; i< nums.length; i++){
if(nums[i] != val){
nums[count] = nums[i];
count++;
}
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment