【Leetcode】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.

 1 class Solution {
 2 public:
 3     int removeElement(int A[], int n, int elem) {
 4         int i = 0;
 5         for (int j = 0; j < n; ++j) {
 6             if (A[j] != elem) {
 7                 A[i++] = A[j];
 8             }
 9         }
10         return i;
11     }
12 };
View Code
原文地址:https://www.cnblogs.com/dengeven/p/3606376.html