Remove Element

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.

Analyse: You have to delete all elements equal to the value and return the new length. 

Runtime: 4ms.

 1 class Solution {
 2 public:
 3     int removeElement(vector<int>& nums, int val) {
 4         int index = 0;
 5         for(int i = 0; i < nums.size(); i++){
 6             if(nums[i] != val)
 7                 nums[index++] = nums[i];
 8         }
 9         return index;
10     }
11 };
原文地址:https://www.cnblogs.com/amazingzoe/p/4777440.html