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.
解题思路:
新建一个newAarryNum,作为新生成数组的下标;
新生数组重新码入除elem以外的元素;
1 class Solution { 2 public: 3 int removeElement(int A[], int n, int elem) { 4 int newArrayNum = 0; 5 6 for (int i=0; i<n; ++i) { 7 if (A[i] != elem) { 8 A[newArrayNum++] = A[i]; 9 } 10 } 11 12 return newArrayNum; 13 } 14 };