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. java基础第10天

    Java异常 Exception 异常指的的在运行期出现的错误,在编译阶段出现的语法错误等,不能称之为异常. 编译类异常 必须处理之后才能正常编译(类找不到,IO异常,在API文档中明确写明throw ...

  2. 转:application/json 四种常见的 POST 提交数据方式

    四种常见的 POST 提交数据方式 HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中 PO ...

  3. [置顶] 【机器学习PAI实践十一】机器学习PAI为你自动写歌词,妈妈再也不用担心我的freestyle了(提供数据、代码

    背景 最近互联网上出现一个热词就是"freestyle",源于一个比拼rap的综艺节目.在节目中需要大量考验选手的freestyle能力,freestyle指的是rapper即兴的 ...

  4. linux screen 命令详解(转载)

    转载于:http://www.cnblogs.com/mchina/archive/2013/01/30/2880680.html 一.背景 系统管理员经常需要SSH 或者telent 远程登录到Li ...

  5. maven安装之后,或者升级之后遇到的问题:could not find or load main class org.codehaus.plexus.class.....

    从maven2升级到maven3或者从maven3降级到maven2,M2_HOME环境变量改变后,在终端执行mvn -v,出现如下错误: Exception in thread "main ...

  6. 6-20 No Less Than X in BST(20 分)

    You are supposed to output, in decreasing order, all the elements no less than X in a binary search ...

  7. 《DSP using MATLAB》Problem 2.18

    1.代码: function [y, H] = conv_tp(h, x) % Linear Convolution using Toeplitz Matrix % ----------------- ...

  8. web程序2

    .

  9. 洛谷4294 [WC2008]游览计划——斯坦纳树

    题目:https://www.luogu.org/problemnew/show/P4294 大概是状压.两种转移,一个是以同一个点为中心,S由自己的子集拼起来:一个是S相同.中心不同的同层转移. 注 ...

  10. vim自定义配置之代码折叠

    vimConfig/plugin/codeFold-setting.vim "--fold setting-- set foldmethod=syntax " 用语法高亮来定义折叠 ...