-
Notifications
You must be signed in to change notification settings - Fork 0
27_RemoveElement
a920604a edited this page Apr 14, 2023
·
1 revision
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int slow = 0, fast = 0, n = nums.size();
while(fast<n){
if(nums[fast] !=val ) nums[slow++] = nums[fast];
fast++;
}
return slow;
}
};
- time complexity
O(n)
- space complexity
O(1)
footer