首页 > 代码库 > 神小逻辑 Remove Duplicates from Sorted Array

神小逻辑 Remove Duplicates from Sorted Array

/*put all vaild new array from the 0 to new length*/public class Solution {    public int removeDuplicates(int[] A) {        if(A.length < 2)            return A.length;         int j = 0;        int i = 1;         while(i < A.length){            if(A[i] == A[j]){                i++;            }else{                A[++j] = A[i++];            }            }         return j+1;    }}

 

神小逻辑 Remove Duplicates from Sorted Array