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; } } }
时间: 2024-10-22 19:54:40