27. Remove Element
Topic Two Pointers
Area Algorithms
Summary
same with 008 question but compare the value with val. not prev.
Problem
Difficulty: Easy
Tags: Array, Two Pointers
Intuition
this one is really easy too. it’s almost same with the 008 one but much easier.
Approach
same with 008 question but compare the value with val. not prev.
Solution
int removeElement(int* nums, int numsSize, int val) {
int counter = 0;
for(int i = 0; i < numsSize ; i++){
if(nums[i] != val){
nums[counter] = nums[i];
counter++;
}
}
return counter;
}
Complexity
-
Time:
-
Space:
Thoughts
easy, next!