Leetcode Problem.27—Remove Element

来源:互联网 发布:复变函数 知乎 编辑:程序博客网 时间:2024/05/18 20:06

Given an array and a value, remove all instances of that value in place and return the new length.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

My C++ solution!

int removeElement(vector<int>& nums, int val)     {        multiset<int> a;        for(int i=0;i<nums.size();i++)           a.insert(nums[i]);a.erase(val);        return a.size();    }


0 0
原创粉丝点击