[leetcode]Remove Duplicates from Sorted Array

简单题。

public class Solution {

    public int removeDuplicates(int[] A) {

        // Start typing your Java solution below

        // DO NOT write main() function

        if (A.length == 0) return 0;

        int i = 0;

        int p = i + 1;

        while (p < A.length)

        {

        	if (A[i] == A[p]) {

        		p++;

        	}

        	else // A[i] !- A[p]

        	{

        		if ( p != i + 1) {

        			A[i+1] = A[p];

        		}

        		i++;

        		p++;

        	}

        }

        return (i+1);

    }

}

  

你可能感兴趣的:(LeetCode)