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

     int removeDuplicates(int A[], int n) {
if(n == )
return ;
if(n == )
return ;
int end = ;
for(int i = ; i < n; i ++) {
if(A[i] != A[end]){
end ++;
A[end] = A[i];
}
}
return end + ;
}

Remove Duplicates from Sorted Array [LeetCode]的更多相关文章

  1. Remove Duplicates From Sorted Array leetcode java

    算法描述: Given a sorted array, remove the duplicates in place such that each element appear only once a ...

  2. Remove Duplicates From Sorted Array

    Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...

  3. [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

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

  4. [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项

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

  5. LeetCode:Remove Duplicates from Sorted Array I II

    LeetCode:Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place su ...

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

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

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

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

  8. LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>

    LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...

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

随机推荐

  1. DirectX 矩阵

    基础: 下标:第一个下标为该元素所在行的索引,第二个下标为该元素所在列的索引.如下图所示 行向量和列向量:只有单行的向量称为行向量,只有单列的称之为列向量. 相等 维数和元素都相等 数乘(与标量相乘) ...

  2. SQL分组查询每组前几条数据

    /*第一种实现方法,效率低并且有错误*/ DECLARE @DD DATETIME SET @DD = GETDATE() SELECT a.GoodsID , a.Account , a.LastU ...

  3. servlet&jsp高级:第二部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  4. 输出sed的重定向

    默认情况下,sed编辑器会将进步的结果输出到STDOUT上,你可以在shll脚本中使用所有重订向sed编辑器输出的标准方法. 你可以在脚本中用反引号来将sed编辑器命令的输出重定向到一个变量中供后面使 ...

  5. iOS - OC 语言新特性

    前言 相对于 Java,OC 语言是一门古老的语言了,而它又是一门不断发展完善的语言.一些新的编译特性,为 OC 语言带来了许多新的活力.在 Xcode7 中,iOS9 的 SDK 已经全面兼容了 O ...

  6. iOS - Swift 与 Objective-C 互相操作

    前言 在 Swift 语言中,我们可以使用 Objective-C.C 语言编写代码,我们可以导入任意用 Objective-C 写的 Cocoa 平台框架.Objective-C 框架或 C 类库. ...

  7. iOS - Swift 面向对象语法

    1.面向对象 面向过程:面向过程编成将所要解决的问题按解决问题的步骤进行分析.如果是大问题,就分解成为多个不同的小问题,在程序里叫做划分成不同的模块.每一个解决的步骤可能是一行或者几行代码,也可能是一 ...

  8. 学习日记day8:移动端页面流程优化

    一:切图 1:切那些(移动端能不用图片就不用图片:logo单独切因为要带链接) 2:普通切(快捷键:复制到新图层  选中 复制 新建 粘贴 保存)  3:类似切 (选中多个图层  矩形框多选  选择工 ...

  9. mysql 主主复制的配置流程

    1.先关闭B,把A的数据导出来,mysqldump -hlocalhost -uroot -p123456 --database ibprpu >ibprpu.sql2.关闭A,启动B,进入my ...

  10. libevent源码安装及Linux自动编译功能总结

    这个..那个..后来发现..直接用jumbo就可以安装libevent.不过,学习一些automake的知识还是有好处的. 03机器也安装了. 这几天在阅读libevent源码,发现参考资料是基于li ...