Skip to content

Latest commit

 

History

History
16 lines (16 loc) · 478 Bytes

35. Search Insert Position.md

File metadata and controls

16 lines (16 loc) · 478 Bytes

思路

排序数组查找肯定就是二分法啦,但是题目没说一定是增序,根据结果来看应该全是增序。

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;
    }
};