题目: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 A = [1,1,2],

Your function should return length = 2, and A is now [1,2].

 class Solution {
public:
int removeDuplicates(int A[], int n) {
if(!n)
return NULL;
int i,num=;
for(i=;i<n;i++)
{
if(A[i]!=A[i-])
{
A[num++]=A[i];
}
}
return num;
}
};

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

  1. 【LeetCode练习题】Remove Duplicates from Sorted List II

    Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...

  2. LeetCode OJ 26. Remove Duplicates from Sorted Array

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

  3. LeetCode OJ 80. Remove Duplicates from Sorted Array II

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

  4. LeetCode OJ:Remove Duplicates from Sorted Array II(移除数组中的重复元素II)

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

  5. LeetCode OJ:Remove Duplicates from Sorted Array(排好序的vector去重)

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

  6. 【26】Remove Duplicates from Sorted Array

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

  7. 【leetcode】Remove Duplicates from Sorted Array II

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

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

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

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

随机推荐

  1. (转)Android分布式编译学习(一)distcc实现分布式编译 —— Ubuntu12.04上部署distcc分布式编译

    转自:http://blog.csdn.net/eqiang8271/article/details/17144411   版权声明:本文为博主原创文章,未经博主允许不得转载. Android代码庞大 ...

  2. Java对象序列化与RMI

    对于一个存在于Java虚拟机中的对象来说,其内部的状态只保持在内存中.JVM停止之后,这些状态就丢失了.在很多情况下,对象的内部状态是需要被持久化下来的.提到持久化,最直接的做法是保存到文件系统或是数 ...

  3. 下载android源码

    http://source.android.com Step 1.按照http://source.android.com/source/initializing.html配置好android编译环境 ...

  4. Python——eventlet.wsgi

    eventlet 的 wsgi 模块提供了一种启动事件驱动的WSGI服务器的简洁手段,可以将其作为某个应用的嵌入web服务器,或作为成熟的web服务器,一个这样的web服务器的例子就是 Spawnin ...

  5. Python装饰器、metaclass、abc模块学习笔记

    (博客原创作品,转载请注明出处!) 最近接触到了Python中的decorator,metaclass,abc Module,six.add_metaclass等内容,这里做一个简单的笔记. 主要资源 ...

  6. python_程序模拟浏览器请求及会话保持

    python下读取一个页面的数据可以通过urllib2轻松实现请求 import urllib2 print urllib2.urlopen('http://www.baidu.com').read( ...

  7. HTTP之referer

    安全培训中提到可以通过referer判断安全性,hackbar中也有一个enable referer的选项,则,这个referer到底是个什么角色? (以下是搜集的一些资料整合,链接均放到底部,不再一 ...

  8. MySQL中show语法使用总结

    MySQL中 show 语法的使用: 先查看MySQL版本信息: mysql> select version(); +------------+ | version() | +--------- ...

  9. UITableView:改变 TableHeaderView 的高度

    参考:http://stackoverflow.com/a/526825 有这么一种需求,在列表顶端显示一些别样的数据,而这个别样的数据则需要通过一个别样的 View 来展现,它便是 UITableV ...

  10. NSNull, Nil, nil, NULL区别(OC)

    参考:http://nshipster.com/nil/ 直接给个表吧 Symbol Value Meaning NULL (void *)0 literal null value for C poi ...