zoukankan      html  css  js  c++  java
  • Remove Duplicates from Sorted Array II

    similar with Remove Duplicates from Sorted Array

     1 public class Solution {
     2     public int removeDuplicates(int[] A) {
     3         // IMPORTANT: Please reset any member data you declared, as
     4         // the same Solution instance will be reused for each test case.
     5         if(A == null)
     6             return 0;
     7         if(A.length < 3)
     8             return A.length;
     9         int slowrunner = 0;
    10         int fastrunner = 1;
    11         boolean hasDup = false;
    12         while(fastrunner < A.length)
    13         {
    14             if(A[slowrunner] == A[fastrunner])
    15             {
    16                 if(hasDup)
    17                     fastrunner++;
    18                 else{
    19                     A[++slowrunner] = A[fastrunner++];
    20                     hasDup = true;
    21                 }
    22             }
    23             else
    24             {
    25                 A[++slowrunner] = A[fastrunner++];
    26                 hasDup = false;
    27             }
    28         }
    29             
    30         return slowrunner+1;
    31     }
    32 }
  • 相关阅读:
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    Java Concurrency
    存储的瓶颈(2)
    存储的瓶颈(3)
  • 原文地址:https://www.cnblogs.com/jasonC/p/3409704.html
Copyright © 2011-2022 走看看