For example, Given sorted array A = [1,1,1,2,2,3],
Your function should return length = 5, and A is...now [1,1,2,2,3]
解决方案:
通过变量index记录每个元素出现的次数
因为是已经排序的数组,所以直接进行相邻元素的总数记录即可!...For example, Given sorted array A = [1,1,1,2,2,3],
Your function should return length = 5, and A is now...[1,1,2,2,3]
*/
function removeDuplicates(arr) {
if(arr.length <= 2) {
return arr.length...= arr[index-2]) {
arr[index++]=arr[i]
}
}
return index
}
const arrs = [1,1,1,2,2,3,4,4,4