C++unordered_map使用例子
来源:互联网 发布:js延迟一秒 编辑:程序博客网 时间:2024/06/16 08:02
1.
#include<tr1/unordered_map>using namespace std;class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> result(2, -1); typedef unordered_map<int, int> Hhashmap; typedef Hhashmap::value_type hmType; typedef Hhashmap::iterator hmIter; Hhashmap hashmap; for (int x=0; x< nums.size(); x++){ hashmap.insert(hmType(nums[x],x)); } for (int j=0; j< nums.size(); j++){ for(hmIter iter=hashmap.begin();iter!=hashmap.end();++iter){ if(iter->first == (target - nums[j]) && j != iter->second){ result[0] = j; result[1] = iter->second; } } } return result; }};
2.
#include<tr1/unordered_map>using namespace std;class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> result(2, -1); typedef unordered_map<int, int> Hhashmap; typedef Hhashmap::value_type hmType; typedef Hhashmap::iterator hmIter; Hhashmap hashmap; for (int x=0; x< nums.size(); x++){ for(hmIter iter=hashmap.begin();iter!=hashmap.end();++iter){ if(iter->first == (target - nums[x]) && x != iter->second){ result[0] = x; result[1] = iter->second; return result; } } hashmap.insert(hmType(nums[x],x)); } return result; }};
阅读全文
0 0
- C++unordered_map使用例子
- c++: unordered_map
- STL: unordered_map 自定义键值类型的使用(C++)
- 【c++】unordered_set和unordered_map
- hash_map,unordered_map的使用
- unordered_map的使用
- unordered_map
- unordered_map
- unordered_map
- unordered_map
- unordered_map -
- unordered_map
- unordered_map
- unordered_map
- unordered_map
- unordered_map
- hash_map和unordered_map的使用
- hash_map/unordered_map原理和使用
- Material Design系列--CollapsingToolbarLayout使用总结
- 1102 Constructing Roads(并查集)
- First Blood
- 2017年网易校招算法编程题:数论 (PHP版)
- Linux运维CentOS系统SVN双备份Shell脚本
- C++unordered_map使用例子
- B-1028
- 位运算求数组中只出现一次的数
- 淘淘商城系列——实现商品详情页面展示
- Android内存管理机制之一:lowmemory killer
- plog库使用总结
- 2017年网易校招算法编程题:优雅的点(PHP版)
- 3371 Connect the Cities(最小生成树)
- Java读写XML代码示例