首页 > 代码库 > leetcode26

leetcode26

public class Solution {
    public int RemoveDuplicates(int[] nums) {
        var len = nums.Length;
            if (len == 0)
            {
                return 0;
            }
            else
            {
                var pre = nums[0];
                var diffindex = 0;
                for (int i = 1; i < nums.Length; i++)
                {
                    if (pre != nums[i])
                    {
                        nums[++diffindex] = nums[i];
                        pre = nums[i];
                    }
                }
                return diffindex + 1;
            }
    }
}

 

leetcode26