We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cd4b25d commit 8c35c01Copy full SHA for 8c35c01
27-remove-element/27-remove-element.cpp
@@ -1,20 +1,13 @@
1
#include <bits/stdc++.h>
2
class Solution {
3
public:
4
- int removeElement(vector<int>& arr, int val) {
5
- int size = 0;
+ int removeElement(vector<int>& nums, int val) {
6
int j = 0;
7
- for(int i=0; i<arr.size(); i++)
8
- {
9
- // cout<<arr[i]<<" ";
10
- if(arr[i] != val)
11
12
- cout<<arr[i]<<" " <<i <<endl;
13
- arr[j] = arr[i];
14
- size+=1;
15
- j+=1;
16
- }
+ for (int i = 0, l = nums.size(); i < l; i++) {
+ if (nums[i] != val)
+ nums[j++] = nums[i];
17
}
18
- return size;
+
+ return j;
19
20
};
0 commit comments