Algorithm: efficient way to remove duplicate integers from an array
2015-07-06 16:17
513 查看
http://stackoverflow.com/questions/1532819/algorithm-efficient-way-to-remove-duplicate-integers-from-an-array
I got this problem from an interview with Microsoft.
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
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
相关文章推荐
- django manage.py 的各种功能
- Sublime Text3 + Golang搭建开发环境
- Django对静态文件的处理——部署阶段
- django框架中,添加用户操作记录和查询功能
- Mongo基本命令
- hdu 1533 Going Home
- fonts.googleapis.com加载慢解决办法
- 【Go】为什么用go; Golang Erlang 前世今生
- history对象back()、forward()、go()方法
- Django模块笔记【四】
- 算法基础:整数排序问题(连续整数只保留首尾两个数字)
- EGOCache如何检测缓存时间过期
- [Django]models定义choices 字典中的页面显示值
- 使用 PyCharm 远程调试 Django 程序
- Binary Tree Traversal Algorithms (二叉树遍历算法)
- 《Fisher Kernels on Visual Vocabularies for Image Categorization》学习笔记
- Google文件系统
- Django模块笔记【三】
- Django模块笔记【二】
- 【Go】 格式处理