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 by modifying the input array in-place with O(1) extra memory.

Example:

Given 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 count = , n = nums.size();
for(int i = ; i < n; i++){
if(nums[i] == nums[i-]) count++;
else nums[i-count] = nums[i];
}
return n-count;
}
};

26. Remove Duplicates from Sorted Array(代码思路新奇)的更多相关文章

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

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

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

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

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

  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. leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法

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

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

  7. 26. Remove Duplicates from Sorted Array

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

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

  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. CF 352 D 罗宾汉发钱 模拟题+贪心

    D. Robin Hood time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. BZOJ 2669 Luogu P3160 [CQOI2012]局部极小值 (容斥原理、DP)

    题目链接 (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=2669 (luogu) https://www.luogu.org/prob ...

  3. Set的遍历以及排序详讲

    java中Set集合是一个不包含重复元素的Collection,首先我们先看看遍历方法 package com.sort;   import java.util.HashSet; import jav ...

  4. SNMP命令

    snmp命令 配置管理网络协议Weblogic项目管理Cisco Snmputil 命令 Snmputil是一个命令行下的软件,使用语法如下: usage: snmputil get|getnext| ...

  5. Gradle项目构建工具学习笔记(持续更新中。。。)

    1.gradle的安装 1)从官网下载gradle,然后解压 2)在系统环境变量新建GRADLE_HOME 3)将%GRADLE_HOME%\bin加入PATH中 2.验证是否安装成功 gradle ...

  6. spring eclipse xml自动提示

    window -> preferences -> XML -> XML Catalog -> 在User Specified Entries新增加一个catalog

  7. 【Spark机器学习速成宝典】模型篇08保序回归【Isotonic Regression】(Python版)

    目录 保序回归原理 保序回归代码(Spark Python) 保序回归原理 待续... 返回目录 保序回归代码(Spark Python) 代码里数据:https://pan.baidu.com/s/ ...

  8. 多个swiper使用样式出了问题

    observer:true,//修改swiper自己或子元素时,自动初始化swiper observeParents:true,//修改swiper的父元素时,自动初始化swiper 不行直接设  w ...

  9. Laravel框架之获取URL地址

    1. 使用 Request 类: $url = Request::getRequestUri(); 2. 使用 $request 对象: public function show(Request $r ...

  10. RF Setup和Teardown的使用

    执行顺序 setup执行顺序是:project级别setup>suite级别setup>case级别setup 无返回值 Run Keywords | [KW1 | arg1 | arg2 ...