提交 28dbc298 编写于 作者: 辉哈's avatar 辉哈

Update 26. Remove Duplicates from Sorted Array

上级 4fd2b0fd
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int n = nums.size(), pos = 0;
if(n <= 1)
return n;
for(int i = 0; i < n-1; ++i) {
if(nums[i] != nums[i+1]) {
nums[++pos] = nums[i+1];
}
}
return pos+1;
}
};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册