zoukankan      html  css  js  c++  java
  • 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 };
  • 相关阅读:
    JS函数式编程【译】前言
    11.15周总结
    11.13
    11.12
    11.11
    11.10
    11.9
    11.8周总结
    11.6
    11.5
  • 原文地址:https://www.cnblogs.com/CathyGao/p/3058865.html
Copyright © 2011-2022 走看看