首页 > 其他 > 详细

LeetCode – Refresh – Two Sum III

时间:2015-03-24 18:55:57      阅读:130      评论:0      收藏:0      [点我收藏+]
 1 class TwoSum {
 2 private:
 3     unordered_map<int, int> record;
 4 public:
 5     void add(int number) {
 6         record[number]++;
 7     }
 8 
 9     bool find(int value) {
10         if (record.size() == 0) return false;
11         for (unordered_map<int, int>::iterator it = record.begin(); it != record.end(); it++) {
12             if (it->first == (value - it->first)) {
13                 if (it->second > 1) {
14                     return true;
15                 }
16             } else if (record.find(value - it->first) != record.end()) {
17                 return true;
18             }
19         }
20         return false;
21     }
22 };

 

LeetCode – Refresh – Two Sum III

原文:http://www.cnblogs.com/shuashuashua/p/4363452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!