Algorithm: efficient way to remove duplicate integers from an array

转载 2015年07月06日 16:17:34

http://stackoverflow.com/questions/1532819/algorithm-efficient-way-to-remove-duplicate-integers-from-an-array

I got this problem from an interview with Microsoft.

Given an array of random integers, write an algorithm in C that removes duplicated numbers and return the unique numbers in the original array.
E.g Input: {4, 8, 4, 1, 1, 2, 9} Output: {4, 8, 1, 2, 9, ?, ?}

One caveat is that the expected algorithm should not required the array to be sorted first. And when an element has been removed, the following elements must be shifted forward as well. Anyway, value of elements at the tail of the array where elements were shifted forward are negligible.

Update: The result must be returned in the original array and helper data structure (e.g. hashtable) should not be used. However, I guess order preservation is not necessary.

Update2: For those who wonder why these impractical constraints, this was an interview question and all these constraints are discussed during the thinking process to see how I can come up with different ideas.


一个大小为N的数组,里面是N个整数,怎样去除重复。

讨论:http://ask.julyedu.com/question/190

Remove Duplicates from Sorted Array [python解]

题目要求:Givena sorted array, remove the duplicates in place such that each element appearonly once and ...
  • nadizhong4136
  • nadizhong4136
  • 2017年07月24日 19:18
  • 273

26. Remove Duplicates from Sorted Array (python)

Given a sorted array, remove the duplicates in place such that each element appear only once and ret...
  • qq_28119401
  • qq_28119401
  • 2016年10月30日 15:58
  • 671

Leetcode—Contains Duplicate—Python的三种写法

方法一: class Solution: # @param {integer[]} nums # @return {boolean} def containsDuplicat...
  • u011581550
  • u011581550
  • 2015年06月17日 20:01
  • 1745

js-remove duplicate array element

Untitled Document var arr = [2,1,2,10,2,3,5,5,1,10,13]; //object // js对象...
  • u014452858
  • u014452858
  • 2015年05月24日 22:50
  • 691

Remove Duplicates from Sorted Array II -- LeetCode

原题链接: http://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/  这道题跟Remove Duplica...
  • linhuanmars
  • linhuanmars
  • 2014年04月23日 08:39
  • 10702

Remove Duplicates from Sorted Array -- LeetCode

原题链接: http://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/  这道题跟Remove Element类似,也是...
  • linhuanmars
  • linhuanmars
  • 2014年02月27日 05:12
  • 10918

LeetCode(26)Remove Duplicates From Sorted Array

题目如下 Given a sorted array, remove the duplicates in place such that each element appear only once an...
  • feliciafay
  • feliciafay
  • 2013年12月31日 08:37
  • 1251

LeetCode 26 — Remove Duplicates from Sorted Array(C++ Java Python)

题目:http://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/ Given a sorted array, remo...
  • dragon_dream
  • dragon_dream
  • 2014年02月23日 15:12
  • 3854

LeetCode:Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and ret...
  • fytain
  • fytain
  • 2013年09月02日 20:42
  • 2757

LeetCode(80) Remove Duplicates From Sorted Array II

题目如下: Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example,...
  • feliciafay
  • feliciafay
  • 2015年01月11日 03:55
  • 1300
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Algorithm: efficient way to remove duplicate integers from an array
举报原因:
原因补充:

(最多只允许输入30个字)