mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
17 lines
474 B
Markdown
17 lines
474 B
Markdown
![]() |
# [Search Insert Position](https://leetcode.com/problems/remove-element/description/)
|
||
|
# 思路
|
||
|
排序数组查找肯定就是二分法啦,但是题目没说一定是增序,根据结果来看应该全是增序。
|
||
|
# C++
|
||
|
```
|
||
|
class Solution {
|
||
|
public:
|
||
|
int removeElement(vector<int>& nums, int val) {
|
||
|
int count = 0;
|
||
|
for(int i = 0; i < nums.size(); i++){
|
||
|
if(nums[i] != val) nums[count++] = nums[i];
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
};
|
||
|
```
|