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){
if(nums.size()==) return ; int ret = ;
int newI = ;
for(int i = ; i < nums.size(); i++){
if(nums[i-]!=nums[i]){
ret++;
nums[newI++] = nums[i];
}
}
return ret;
}
};

26.Remove Duplicates from Sorted Array(Array)的更多相关文章

  1. [Leetcode][Python]26: Remove Duplicates from Sorted Array

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...

  2. 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++> 给出排序好的 ...

  3. 26. Remove Duplicates from Sorted Array【easy】

    26. Remove Duplicates from Sorted Array[easy] Given a sorted array, remove the duplicates in place s ...

  4. leetCode练题——26. Remove Duplicates from Sorted Array

    1.题目 26. Remove Duplicates from Sorted Array--Easy Given a sorted array nums, remove the duplicates  ...

  5. 26. Remove Duplicates from Sorted Array

    题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  6. C# 写 LeetCode easy #26 Remove Duplicates from Sorted Array

    26.Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place suc ...

  7. [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 ...

  8. leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法

    Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...

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

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

  10. 【leetcode】 26. Remove Duplicates from Sorted Array

    @requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ...

随机推荐

  1. 使用Pandas: str.replace() 进行文本清洗

    前段时间参加了Kaggle上的Mercari Price Suggestion Challenge比赛,收获良多,过些时候准备进行一些全面的总结,本篇文章先谈一个比赛中用到的小技巧. 这个比赛数据中有 ...

  2. STL标准库-容器-unordered_set

    技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性 unordered_set与与unordered_map相似,这次主要介绍unordered_set unordered_set ...

  3. jQuery 参数详解

    url: 要求为String类型的参数,发送请求的地址.如果没有填写, 默认发送当前页的url type: 要求为String类型的参数,请求方式(post或get)默认为get. 注意其他http请 ...

  4. Centos 7中的网卡一致性命名规则

    一致性网络设备命名,即Consistent Network Device Naming 一.为什么需要这个 服务器通常有多块网卡,有板载集成的,同时也有插在PCIe插槽的. Linux系统的命名原来是 ...

  5. 使用c++实现一个FTP客户端(二)

    接上篇http://www.cnblogs.com/jzincnblogs/p/5213978.html,这篇主要记录编程方面的重点. 客户端使用了Windows Socket提供的API,支持上传. ...

  6. 360插件化Replugin爬坑之路

    前言 继上次爬完了热修复的坑位,中途爬了各种各样的坑.今天我们来说说插件化Replugin的坑位.Replugin刚出的时候我就看过了.第一次看的时候可能心态不好.没看懂= =第二次重头在看,发现蛮简 ...

  7. Java第六次作业--异常处理和Java类集

    Deadline: 2017-5-4 23:00 一.学习要点 认真看书并查阅相关资料,掌握以下内容: 理解Java的异常处理机制 掌握捕获异常和声明抛出异常的方法 掌握List接口的实现类Array ...

  8. POI2014题解

    POI2014题解 [BZOJ3521][Poi2014]Salad Bar 把p当作\(1\),把j当作\(-1\),然后做一遍前缀和. 一个合法区间\([l,r]\)要满足条件就需要满足所有前缀和 ...

  9. HDU3530 Subsequence(单调队列)

    题意是说给出一个序列,现在要求出这个序列的一个最长子区间,要求子区间的最大值与最小值的差在[m, k]范围内,求区间长度 做法是维护两个队列,一个维护到当前位置的最大值,一个维护最小值,然后计算当前节 ...

  10. jQuqery append 和 after 区别

    jQuqery append 和 after 区别 append 是在被选元素内的结尾插入内容. 比如以下选中了 ol 元素,使用 append 后会在 <li> List Item 2 ...