Leetcode#27 Remove Element

原题地址

 

基本模拟题,双指针法

 

代码:

 1 int removeElement(int A[], int n, int elem) {

 2         int i = 0;

 3         int j = 0;

 4         

 5         while (i < n) {

 6             if (A[i] == elem)

 7                 i++;

 8             else {

 9                 A[j] = A[i];

10                 j++;

11                 i++;

12             }

13         }

14         

15         return j;

16 }

 

你可能感兴趣的:(LeetCode)