LeetCode Remove Element

Easy!

O(n)

 1 class Solution {
 2 public:
 3     int removeElement(int A[], int n, int elem) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         
 7         int p=0;
 8         int q=0;
 9         while(q<n)
10         {
11             if(A[q]==elem)
12             {
13                q++;
14             }
15             else
16             {
17                 A[p] = A[q];
18                 p++; q++;
19             }
20         }
21         
22         return p;
23     }
24 };
原文地址:https://www.cnblogs.com/CathyGao/p/3058865.html