mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
474 B
474 B
Search Insert Position
思路
排序数组查找肯定就是二分法啦,但是题目没说一定是增序,根据结果来看应该全是增序。
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;
}
};