标签:sorted from duplicate java asc dup dex 元素 index
原地移除元素,返回新长度
const removeDuplicates = nums => {
let index = 1;
for (let i = 0; i < nums.length - 1; i++) {
if (nums[i] != nums[i + 1]) {
nums[index++] = nums[i + 1];
}
}
nums.length = index
return index;
};
leetcode 26. Remove Duplicates from Sorted Array
标签:sorted from duplicate java asc dup dex 元素 index
原文地址:https://www.cnblogs.com/rubylouvre/p/12041754.html