def removeDuplicates(self, A):
        length = len(A)
        if length<=2:
            return length

        close_ptr = 0
        duplicate_once = False  # flag
        for open_ptr in range(close_ptr+1, length):
            if A[close_ptr]!=A[open_ptr]:  # found non-duplicate
                duplicate_once = False
                close_ptr += 1
                A[close_ptr] = A[open_ptr]
            elif not duplicate_once:  # found duplicate, but not duplicated before
                duplicate_once = True
                close_ptr += 1
                A[close_ptr] = A[open_ptr]
            else:  # found duplicate, and duplicated before, continue searching
                continue  # find next non-duplicate

        return close_ptr+1
Two pointers algorithm, open_ptr & closed_ptr
dataset/ETHPy150Open algorhythms/LeetCode/081 Remove Duplicates from Sorted Array II.py/Solution.removeDuplicates