原地移除元素,返回新长度
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;
};