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

相关文章推荐

LeetCode 26 remove Duplicate from sorted array

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

Leetcode 第二章线性表--2.1数组---2.1.1 remove duplicate from sorted array--2017/7/23

2.1.1 Remove Duplicates from Sorted Array 描述: Given a sorted array, remove the duplicates in place s...

【Leetcode Algorithm】Remove Duplicates from Sorted Array

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

Is-there-any-way-to-prevent-an-android-app-from-being-removed

Is-there-any-way-to-prevent-an-android-app-from-being-removed

Mac OS X: Best Way to Make an ISO from a CD or DVD

http://superuser.com/questions/85987/mac-os-x-best-way-to-make-an-iso-from-a-cd-or-dvd ...

Q2.1 Write code to remove duplicates from an unsorted linked list.

Q: Write code to remove duplicates from an unsorted linked list. FOLLOW UP How would you solve th...

How to manually remove an infected file from your computer

How to manually remove an infected file from your computer In order to manually remove an infected ...

转载:how to automate Microsoft Excel and return the values from a multi-cell range to an array

how to automate Microsoft Excel and return the values from a multi-cell range to an array.
  • buyicn
  • buyicn
  • 2011年05月01日 16:30
  • 471

An Energy-Efficient Ant-Based Routing Algorithm for Wireless Sensor Networks (无线传感网中基于蚁群算法的能量有效路由)2

牙说:接着上一篇继续写。 论文标题:An Energy-Efficient Ant-Based Routing Algorithm forWireless Sensor Networks 作者:Tia...
  • ljm1995
  • ljm1995
  • 2017年04月20日 18:29
  • 520
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Algorithm: efficient way to remove duplicate integers from an array
举报原因:
原因补充:

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