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. 正向代理、Nginx(反向代理、负载均衡、静态资源服务器)

    淘宝tengine文档(本质就是淘宝版的Nginx) http://tengine.taobao.org/book/index.html

  2. 什么是web接口

    当我们在请求一个页面的时候,会显示服务器返回的资源,其中包含了HTML.CSS和JS,除此之外,服务器还可以返回图片.视频.字体和插件等类型的资源.这些资源全部由HTTP协议传输. 如果把HTTP协议 ...

  3. [intellij]create gradle project

    https://intellij-support.jetbrains.com/hc/en-us/community/posts/206806425/comments/206797339

  4. Django CSRF cookie not set.错误

    post提交表单报错: Forbidden (403) CSRF verification failed. Request aborted. You are seeing this message b ...

  5. mapreduce 运行-指定各种运行参数

    mapreduce指定参数 mapreduce在运行的时候可以指定各种参数,这样可以根据实际的应用场景做一下相关的调整 1.指定运行时cpu的个数 hadoop jar hadoop-core-0.1 ...

  6. 对 Java Integer.valueOf() 的一些了解

    从一道选择题开始 分析 选项A   选项A中比较的是i01和i02,Integer i01=59这里涉及到自动装箱过程,59是整型常量,经包装使其产生一个引用并存在栈中指向这个整型常量所占的内存,这时 ...

  7. 微信小程序获取验证码倒计时

    getVerificationCode: function() { var that = this; var currentTime = that.data.currentTime; that.set ...

  8. GPU:并行计算利器

    http://blog.jobbole.com/87849/     首页 最新文章 IT 职场 前端 后端 移动端 数据库 运维 其他技术 - 导航条 - 首页 最新文章 IT 职场 前端 - Ja ...

  9. 【Java】仿真qq尝试:用户注册(二)

    参考: 1.corejavaI:使用解耦的try/catch与try/finally 2.Java中try catch finally语句中含有return语句的执行情况(总结版):http://bl ...

  10. MapReduce:给出children-parents(孩子——父母)表,要求输出grandchild-grandparent(孙子——爷奶)表

    hadoop中使用MapReduce单表关联案例: MapReduce:给出children-parents(孩子——父母)表,要求输出grandchild-grandparent(孙子——爷奶)表. ...