# 关小刷刷题07 – Leetcode 26. Remove Duplicates from Sorted Array 方法1

## 题目

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.

## 方法1

```class Solution {
public:
int removeDuplicates(vector<int>& nums) {
return unique(nums.begin(), nums.end())-nums.begin();
}
};```

0 条评论

## 相关文章

4316

2823

### Sweet Snippet 之 Bounce Setting

又是一篇Sweet Snippet，自己看来都觉得过小，不足以成篇，不过自觉有些趣味，也就随便记一记了，权当自娱自乐 ：）

611

523

### CodeForces 982F：The Meeting Place Cannot Be Changed（有向图）

Petr is a detective in Braginsk. Somebody stole a huge amount of money from a ba...

961

### 算法系列

算法对程序员来说是熟悉的陌生人，编过大量代码后突然被哪个问到算法是什么也有时不知从何说起，简单来说是没有好好总结过仔细分析过。大学里面导师整天苦口婆心的教导...

23310

3616

2365

2693

3678