LeetCode Remove Duplicates from Sorted Array

class Solution {
public:
    int removeDuplicates(int A[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
       
       if (n == 0)    return 0;

        int p=0;
        int q=1;

        while(q<n)
        {
            if(A[q]==A[p])
            {
                q++;
            }
            else
            {
                p++;
                A[p] = A[q];
                q++;
            }
        }
        
                
        return (p+1);
    }
};

Attention: edge case!!!

inputoutputexpected 
[] [0] []
 Wrong!
原文地址:https://www.cnblogs.com/CathyGao/p/3058875.html