[InterviewBit] Remove Element from Array

Remove Element from Array

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
int Solution::removeElement(vector<int> &A, int B) {
int res = 0;
for(int i = 0; i < A.size(); i++) {
if(A[i] == B) continue;
A[res++] = A[i];
}
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/27/PS/interviewbit/remove-element-from-array/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.