一道关于运用Hashtable的题目
来源:互联网 发布:中国网络菜市场2017 编辑:程序博客网 时间:2024/05/17 22:44
You are given an array of integers and a sum. Find all pairs of integers that equal that sum. Assume you have some sort of data structures that will be able to store the pairs. Write an algorithm to find all these pairs.
这道题好像和我博客里面的另一道题有冲突,不过这里我放另外一个扩展性问题就是:
如果是三个数字,而不是两个数字相加呢,或者是找出4个数字相加起来为target的值的,据说要用到DP(Dynamic Programming)
以下是大致思路,感觉还靠谱
input : a[], target
: for(int i = 0; i < a.length; i++)
: for(int j = 0; j < a.length; j++)
: {
: sum = a[i] + a[j];
: if(hashmap.find(target-sum))
: The four number is a[i], a[j], and the the element with index
from
: hashmap.getKey(target-sum)
: else
- 一道关于运用Hashtable的题目
- 关于继承的一道题目
- 一道关于排序的题目
- 关于fork的一道题目
- 一道关于继承的题目
- 笔试的一道关于测试的题目
- 关于byte的一道有趣的题目
- 一道关于时间复杂度的数据结构题目
- 一道面试题目,关于this的理解
- 关于函数声明表达式的一道题目
- 一道关于实例化顺序的题目
- 关于腾讯面试的一道题目
- 关于Notify() wait()的一道面试题目
- 关于指针加减的一道题目
- 关于金山的一道面试题目
- 关于金山的一道面试题目
- 关于中国象棋的一道微软面试题目
- 一道关于加载顺序的题目分析
- 使用getconf DISK_SIZE /dev/updisk2确定一个不属于任何卷组的物理卷大小
- 小诗一首---观立体成像
- Java CRC_16生成函数
- 给linux初学者的一点小小的建议
- word文档.doc可能包含与纯文本格式不兼容的问题
- 一道关于运用Hashtable的题目
- Redmine配置(Windows xp环境)
- strcpy实现
- (索引)OpenGL学习资料
- Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects
- 不用临时变量将两个int数字交换
- 解决文本框在updatepanel中得到焦点,输入法不能切换到中文的问题
- 保姆型项目经理
- qqqqqqqqqqq