Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Remove Duplicates from Sorted Array

public int RemoveDuplicates(int[] nums) 
{
  int i=0,j=1;
  while(j<nums.Length)nums[++i]=nums[j++]==nums[--i] ? nums[i]:nums[j+i-++i];
  return i+1;
}

i am freindly code below
public class Solution 
{
    public int RemoveDuplicates(int[] nums) 
    {
        int i=0,j=1;
        while(j<nums.Length)
        {
            if(nums[j]==nums[i]) j++;
            else nums[++i] =nums[j++];
        }
        return i+1;
    }
}
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #Remove #Duplicates #Sorted #Array
ADD COMMENT
Topic
Name
6+9 =