1
// two pointer
2
class Solution {
3
public:
4
int removeElement(vector<int> &nums, int val) {
5
int left = 0;
6
int right = nums.size() - 1;
7
while (left <= right) {
8
if (nums[left] != val) {
9
++left;
10
} else if (nums[right] == val) {
11
--right;
12
} else if (left < right) {
13
nums[left++] = nums[right--];
14
}
15
}
16
return left;
17
}
18
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0