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.

简单的双指针题目,没什么好说的:

 class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int sz = nums.size();
if(sz == || size == ) return sz;
int j = ;
for(int i = ; i < sz; ++i){
if(nums[i] != nums[i-])
nums[j++] = nums[i];
}
return j;
}
};

LeetCode OJ:Remove Duplicates from Sorted Array(排好序的vector去重)的更多相关文章

  1. LeetCode OJ Remove Duplicates from Sorted Array II

    Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...

  2. LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>

    LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...

  3. LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++>

    LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的 ...

  4. [LeetCode] 80. Remove Duplicates from Sorted Array II ☆☆☆(从有序数组中删除重复项之二)

    https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/discuss/27976/3-6-easy-lines-C% ...

  5. [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项 II

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...

  6. [LeetCode] 26. Remove Duplicates from Sorted Array ☆(从有序数组中删除重复项)

    [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项 描述 Given a sorted array nums, remove the d ...

  7. [leetcode] 80. Remove Duplicates from Sorted Array II (Medium)

    排序数组去重题,保留重复两个次数以内的元素,不申请新的空间. 解法一: 因为已经排好序,所以出现重复的话只能是连续着,所以利用个变量存储出现次数,借此判断. Runtime: 20 ms, faste ...

  8. [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...

  9. [LeetCode] 26. Remove Duplicates from Sorted Array 有序数组中去除重复项

    Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...

  10. 【leetcode】Remove Duplicates from Sorted Array II

    Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...

随机推荐

  1. 用仿ActionScript的语法来编写html5——第六篇,TextField与输入框

    一,对比1,html5中首先看看在html5的canvas中的文字显示 var canvas = document.getElementById("myCanvas"); var ...

  2. django的序列化问题

    Django中的序列化主要应用在将数据库中检索的数据返回给客户端用户,特别的Ajax请求一般返回的为Json格式 1.serializers from django.core import seria ...

  3. 算法题 21 findNSum (好未来,LeetCode,牛客网)

    一.三数之和:LeetCode 15 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. ...

  4. 基本数据类型(Day4)

    一 什么是数据? eg:x=10     则10是要存储的数据 二 为什么数据要分不同的类型? 数据是用来表示不同状态的,当然不同的状态可以用不同的数据表示 三 数据类型 1.数字(整型,长整型 ,浮 ...

  5. SqlHelper简单实现(通过Expression和反射)5.Lambda表达式解析类

    这个ExpressionHelper类,是整个SqlHelper中,最核心的一个类,主要功能就是将Lambda表达式转换为Sql语句.同时这个转换过程比较复杂,所以下面详细讲解一下思路和这个类的作用. ...

  6. ruby安装神器rvm,你造吗?

    以前的一篇文章介绍过如何安装ruby,叫做:如何安装/更新ruby,安装cocoapods,为开发做好准备!(2016年12月07日更新内容) 文章中讲到的方法依然可行,但是该方法繁琐并且可能会出现各 ...

  7. SQL语句2

    1. SELECT * FROM Persons WHERE City NOT LIKE '%lon%' 2. SELECT * FROM Persons WHERE FirstName LIKE ' ...

  8. Thrift简单调用

    pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...

  9. Apache 静态缓存配置

    静态文件缓存 静态缓存在客户端下进行缓存,可以设置缓存文件类型与缓存时间,提升客户端访问站点速度. 语法格式 ExpiresByType type/encoding “<base> [pl ...

  10. 20145219 《Java程序设计》第07周学习总结

    20145219 <Java程序设计>第07周学习总结 教材学习内容总结 认识时间与日期 时间的度量 1.格林威治时间(GMT):通过观察太阳而得,因为地球公转轨道为椭圆形且速度不一,本身 ...