题目: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. oracle PLSQL基础学习

    --oracle 练习: /**************************************************PL/SQL编程基础************************** ...

  2. Python——uuid

    uuid模块在Python 2.5以后引入,接口包括:不可变对象UUID(UUID类)和函数uuid1().uuid3().uuid4()和uuid5(),后面的四个函数用于生成 RFC 4122 规 ...

  3. 如何使用 OpenFileDialog 组件 (选择文件组件)

        向程序设计窗体中添加一个OpenFileDialog控件,在属性对话框中设置其Filter属性为 "所有文件(*.*)|*.*|文本文件(*.txt)|*.txt|WPS文档(*.w ...

  4. resharper安装后,F12不能转到定义,也不是反编译,而是转到对象浏览器(object browser)

    问: resharper安装后,一不小心点错了(选择了object browser)以上配置在哪里设置?转到定义用习惯了. 回答 :打开Resharper,选择Options,然后选择Tools中的E ...

  5. topK 算法

    搜索引擎热门查询统计 题目描述:    搜索引擎会通过日志文件把用户每次检索使用的所有检索串都记录下来,每个查询串的长度为1-255字节.    假设目前有一千万个记录(这些查询串的重复度比较高,虽然 ...

  6. js模拟键盘事件

    <!DOCTYPE html> <html> <head lang="zh-CN"> <meta charset="UTF-8& ...

  7. Jenkins+Github配置【转】

    一.GitHub上配置 前提:Jenkins能正常打开 将本地文件上传到GitHub上:进入终端 cd Documents cd project git clone https://github.co ...

  8. unity3d 调用Start 注意

    在unity3d中,同一个脚本被绑定到多个物体上的时候,只有active的物体才会调用void Start ()  方法, 如果物体是NO Active 的状态,则不会调用Start,Awake也不会 ...

  9. 动态为页面添加CSS样式文件引用

    动态为页面添加CSS样式文件引用: if (document.createStyleSheet) { //IE document.createStyleSheet("./Themes/Def ...

  10. 18 如何使用go来采集windows的基本硬件信息后发送到CMDB的服务器上

    preface 之前我使用python写了cmdb采集的脚本,打包成exe的二进制文件后放在windows上执行,也达到了预期的效果. 但是最近部门要上open-falcon监控体系,每个服务器都要安 ...