Java Solution - 270ms


  • 0
    D
    public class Solution {
        public int removeDuplicates(int[] A) {
            int len=A.length;
            if(len==0) return 0;
            int prev=A[0],res=1,val;
            for(int i=1;i<len;i++){
                val = A[i];
                if(prev!=val){
                    prev=val;
                    A[res]=val;
                    res++;
                }
            }
            return res;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.