Skip to content

Commit

Permalink
Time: 3 ms (70.00%), Space: 8.9 MB (37.34%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
ArbitCode committed Dec 17, 2022
1 parent fb035ec commit 35d68b2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 0027-remove-element/0027-remove-element.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
//find k, interate over array if ele not val replace
int removeElement(vector<int>& nums, int val) {
int valc = 0;
for(auto it : nums) if(it == val) valc++;
int k = nums.size() - valc;
int j = 0;
for(int i = 0; i < nums.size() && j < k; i++){
if(nums[i] == val) continue;
nums[j++] = nums[i];
}

return k;
}
};

0 comments on commit 35d68b2

Please sign in to comment.