LC--begin 01 two sum

··brute force--强力暴力

··IllegalArgumentException--不合法的参数

   throw new IllegalArgumentException(" no two num solution");

返回数组下标。下标就是i,j和,暴力完全能想到啊。。被leetcode给吓到了,也被c++的大家vecctor的解析吓到了

时间复杂度O(n2)

 

two-pass hash table --二次哈希表--两个iterator--俩for循环

 improve run time complexity---减小时间复杂度,空间换取时间。

chect if the complement exist in the array(补充,补足)

hash table can maintain a mapping of each element in the array to its index--

哈希表能够保持一个   数组元素与索引的映射

hashmap和hashtable区别

【1.hashMap去掉了HashTable 的contains方法,但是加上了containsValue()和containsKey()方法。
2.hashTable同步的,而HashMap是非同步的,效率上比hashTable要高。
3.hashMap允许空键值,而hashTable不允许。】

containsValue()  true

containsKey() true

get(key)---value

Map<integer,integer> map=new HashMap<>();

同样也需要IllegalArgumentException("cvbvcvvc");

 

一次哈希表--使用一个iterator

先看map是否contains ,如果不,put,否则返回

//第二次重新做的时候,发现了一些错误:

如下:

·Map<Integer,Integer> map=new HashMap<>();

·因为HashMap不存在根据value取值,而本题因为map中能够保存的value一定不一样,所以考虑不是把索引变成key,而是用nums[i]作为key,i作为value

 即get(Object key);

·有可能最后没办法放回,所以循环结束加上 throw new IlllegalArgumentException(" cxxxxxx");

总之就是--看完解答感觉好简单

 

posted @ 2016-09-22 14:44  Nicolellu  阅读(177)  评论(0编辑  收藏  举报