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.

题意:消除数组中所有重复的数字,重复数字只留一个

这样的题用Python好简单啊

直接用集合set消除重复的数字就好了

 class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
l={i for i in nums}
n=len(l)
l = list(l)
l.sort()
nums=l
return n

用C也挺简单的

 int removeDuplicates(int* nums, int numsSize) {
int i=,j=;
int flag=INT_MIN;
for(i=;i<numsSize;i++){
if(nums[i]!=flag){
nums[j]=nums[i];
j++;
}
flag=nums[i];
}
return j;
}

【LeetCode】26. Remove Duplicates from Sorted Array的更多相关文章

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

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

  2. 【LeetCode】26. Remove Duplicates from Sorted Array 解题报告(Python&C++&Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https:// ...

  3. 【LeetCode】80. Remove Duplicates from Sorted Array II (2 solutions)

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

  4. 【LeetCode】080. Remove Duplicates from Sorted Array II

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

  5. 【一天一道LeetCode】#26. Remove Duplicates from Sorted Array

    一天一道LeetCode系列 (一)题目 Given a sorted array, remove the duplicates in place such that each element app ...

  6. 【LeetCode】80. Remove Duplicates from Sorted Array II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  7. 【LeetCode】83 - Remove Duplicates from Sorted Array

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

  8. 【LeetCode】026. Remove Duplicates from Sorted Array

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

  9. 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...

随机推荐

  1. Unity中的Mathf类

    Mathf.Abs绝对值 计算并返回指定参数 f 绝对值. Mathf.Acos反余弦 static function Acos (f : float) : float 以弧度为单位计算并返回参数 f ...

  2. java的三种构造器

    重叠构造器:不可取: javabeans模式:不可取: Builder模式:可取.

  3. java程序基础

  4. 浏览器的云加速可能导致IP统计异常

    前段时间弄个流量统计相关的东西,请求展示图片时根据请求的IP进行 md5 签名生成点击链接的验证参数,结果发现一个莫名其妙的问题 发现点击日志中有一小部分点击的IP居然不一致,如果是开放给别人用可能存 ...

  5. JSON.toJSONString的jar包问题

    toJSONString()方法的jar包不在json-lib中,简单点阿里巴巴给我们封装好的json包,也是开源的alibaba.fastjson.JSON,网上搜fastjson应该就有了.

  6. [SOJ] 无路可逃?

    Description 唐僧被妖怪关在迷宫中.孙悟空好不容易找到一张迷宫地图,并通过一个魔法门来到来到迷宫某个位置.假设迷宫是一个n*m的矩阵,它有两种地形,1表示平地,0表示沼泽,孙悟空只能停留在平 ...

  7. [转] windows 上用程序putty使用 ssh自动登录Linux(Ubuntu)

    需求: 在Win7电脑上使用putty(一种ssh客户端)连接Ubuntu 工具: puttygen.exe 和 putty.exe 第一步:生成密匙 运行puttygen.exe,选择需要的密匙类型 ...

  8. javascript和jquery比较中学习

    获取input的值: document.getElementById("id").value;这里查的是input的name属性 $('input').val(); 设置input ...

  9. non-ARC代码转 ARC 排除 “Existing instance variable 'delegate' for property with assign attribute must be _unsafe _unretained” 错误

    原来非ARC代码是 @interface MHWebImageDownloader : NSObject { id<MHWebImageDownloaderDelegate> delega ...

  10. SnackbarUtils:一行代码搞定Snackbar

    此文章是我在简书的文章 http://www.jianshu.com/p/f4ba05d7bbda Snackbar在Android中的使用日益广泛,很大程度上替代了传统的Toast,相比Toast拥 ...