My Simple C++ Solution. Beats 68.11% in 3 ms


  • 0
    S
    class Solution {
    public:
        int removeElement(vector<int>& nums, int val) {
            int count = 0;
            sort(nums.begin(), nums.end());
            for(int i = 0; i < nums.size(); i++){
                if(nums[i] == val) count++;
                if(nums[i] > val) nums[i - count] = nums[i];
            }
            return nums.size() - count;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.