0027 Remove Element
问题概述
解题思路
class Solution
{
public:
int removeElement(std::vector<int>& nums, int val) //引用传递
{
for (int i = 0; i < nums.size(); i++)
{
if (nums[i] == val)
{
for (int j = i + 1; j < nums.size(); j++)
{
nums[i] = nums[j];
}
nums.pop_back();
i--;
}
}
return nums.size();
}
};