原题地址

 

基本模拟题,双指针法

 

代码:

 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 }

 

相关文章:

  • 2021-10-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2022-12-23
猜你喜欢
  • 2021-06-17
  • 2021-06-17
  • 2021-07-23
  • 2021-05-31
  • 2022-01-05
  • 2021-06-10
  • 2021-06-16
  • 2022-03-02
相关资源
相似解决方案