문제 링크
요약
- 쉬운 문제
최종
결과
- 이 문제는 LeetCode 26 처럼 접근하면 된다: 그냥
val이랑 다른 값이 나올때마다 앞에서부터 덮어씌워주면 된다.
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int cnt = 0;
for (int num : nums) {
if (num != val) {
nums[cnt] = num;
cnt++;
}
}
return cnt;
}
};