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 ffbc7aa commit a636a54Copy full SHA for a636a54
27-remove-element/27-remove-element.cpp
@@ -1,20 +1,16 @@
1
#include <bits/stdc++.h>
2
class Solution {
3
public:
4
- int removeElement(vector<int>& arr, int val) {
5
- int size = 0;
6
- int j = 0;
7
- for(int i=0; i<arr.size(); i++)
8
- {
9
-
10
- if(arr[i] != val)
11
12
- cout<<arr[i]<<" " <<i <<endl;
13
- arr[j] = arr[i];
14
- size+=1;
15
- j+=1;
+ int removeElement(vector<int>& nums, int val) {
+ int k=0;
+ for(int i=0; i<nums.size(); i++){
+ if(nums[i] == val){
+ continue;
+ }else{
+ nums[k] = nums[i];
+ k += 1;
16
}
17
18
- return size;
+ return k;
19
20
};
0 commit comments