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. 读取excel到数据库里面

    //读取excel数据到dataTable里面 public DataTable ReadExcelDataToDataTable(string path) { DataTable dt = new ...

  2. adb shell input keyevent code详解

    adb shell input keyevent 7 # for key '0' adb shell input keyevent 8 # for key '1' adb shell input ke ...

  3. IBM Lotus Domino V8.5 服务器管理入门手册

    转自 http://freemanluo.blog.51cto.com/636588/336128

  4. JUnit 简单的使用 (学习转载)

    JUnit4使用Java5中的注解(annotation),以下是JUnit4常用的几个annotation: @Before:初始化方法   对于每一个测试方法都要执行一次(注意与BeforeCla ...

  5. NYOJ 93 汉诺塔(三)

    汉诺塔(三) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度 ...

  6. mac系统如何进行剪切

    来源: http://jingyan.baidu.com/article/1612d5007f76e7e20e1eeeca.html 分步阅读 mac os x下没有像windows中现成的“剪切”命 ...

  7. iOS - Swift 数据持久化

    1.Sandbox 沙箱 iOS 为每个应用提供了独立的文件空间,一个应用只能直接访问为本应用分配的文件目录,不可以访问其他目录,每个应用自己独立的访问空间被称为该应用的沙盒.也就是说,一个应用与文件 ...

  8. struts2 if标签示例

    下面总结一下struts2 中if标签的使用 (1)判断字符串是否为空 <s:if test="user.username==null or user.username==''&quo ...

  9. QQServer_update

    import java.awt.*; import javax.swing.*; import java.net.*; import java.io.*; import java.awt.event. ...

  10. wpf datagrid 如何让标头 及内容居中

    头就是这么居中<DataGrid> <DataGrid.ColumnHeaderStyle> <Style TargetType="DataGridColumn ...