Leetcode链接:26. 删除有序数组中的重复项 - 力扣(LeetCode)
难易程度:简单
1 public int removeDuplicates(int[] nums) { 2 if (nums == null || nums.length <= 1) { 3 return 0; 4 } 5 6 int len = nums.length; 7 // 使用双指针解决,next指针会一直不断向后寻找不等的值 8 int cur = 0; 9 int next = cur + 1; 10 while (next < len) { 11 if (nums[cur] != nums[next]) { 12 // 找到以后直接将cur的下一个值替换为nums[next] 13 nums[++cur] = nums[next]; 14 } 15 next++; 16 } 17 return cur + 1; 18 }
标签:删除,nums,重复,元素,int,数组 From: https://www.cnblogs.com/luckybobby/p/17121357.html