七公子706

关注

lc26删除有序数组中的重复项

七公子706

关注

阅读 115

2023-02-13

class Solution {
public int removeDuplicates(int[] nums) {
if (nums.length == 0) {
return 0;
}
int slow = 0, fast = 0;
while (fast < nums.length) {
if (nums[fast] != nums[slow]) {
slow++;
// 维护 nums[0..slow] 无重复
nums[slow] = nums[fast];
}
fast++;
}
// 数组长度为索引 + 1
return slow + 1;
}
}


相关推荐

柠檬果然酸

26.删除有序数组中的重复项

柠檬果然酸 65 0 0

汤姆torn

26. 删除有序数组中的重复项

汤姆torn 59 0 0

天蓝Sea

Leetcode 26.删除有序数组中重复项

天蓝Sea 48 0 0

月孛星君

LeetCode:26. 删除有序数组中的重复项

月孛星君 72 0 0

茗越

Leetcode26:删除有序数组的中重复项

茗越 36 0 0

我是芄兰

LeetCode 26. 删除有序数组中的重复项

我是芄兰 23 0 0

崭新的韭菜

leetcode_26_删除有序数组中的重复项

崭新的韭菜 67 0 0

覃榜言

LeedCode26. 删除有序数组中的重复项

覃榜言 28 0 0

千妈小语

【LeeCode】26. 删除有序数组中的重复项

千妈小语 89 0 0

草原小黄河

LeetCode 26.删除有序数组中的重复项

草原小黄河 67 0 0

精彩评论(0)

0 0 举报