关闭

Algorithm: efficient way to remove duplicate integers from an array

245人阅读 评论(0) 收藏 举报
分类:

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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:13652次
    • 积分:220
    • 等级:
    • 排名:千里之外
    • 原创:5篇
    • 转载:28篇
    • 译文:0篇
    • 评论:0条
    文章分类