题目内容:
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array nums = [1,1,2],
Your function should return length = 2, with the first two elements of
nums being 1 and 2 respectively. It doesn't matter what you leave beyond the new length.
题目分析:注意数组是已经经过排序的数组,可以使用两个指针来对不重复的数字个数进行甄别。其中一个指针扫描数组的每一个元素,另外一个指针用来改变数组中的值,是的最终这个指针只想不同元素的最后一个位置。
题目代码:

本文介绍了一种在不使用额外空间的情况下从已排序数组中删除重复元素的方法。通过使用双指针技巧,该方法能有效地遍历数组并保持唯一元素的连续性。最终返回不含重复项的数组长度。
1106

被折叠的 条评论
为什么被折叠?



