LeetCode Remove Element
Description
Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn’t matter what you leave beyond the new length.
The original problem is here.
The original code is here.
My Solution
I solve this problem in C++, as below:
/*
*Remove Element
*Author: shuaijiang
*Email: zhaoshuaijiang8@gmail.com
*/
class Solution {
public:
int removeElement(int A[], int n, int elem) {
int new_len = 0;
for(int count=0;count<n;++count)
{
if(A[count] != elem)
{
A[new_len] = A[count];
new_len ++;
}
}
return new_len;
}
};
Note
Just keep patient!
LeetCode Remove Element
http://zhaoshuaijiang.com/2015/04/03/leetcode_remove_element/