170. Two Sum III - Data structure design

Posted 我的名字叫周周

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了170. Two Sum III - Data structure design相关的知识,希望对你有一定的参考价值。



public
class TwoSum { private HashMap<Integer, Integer> elements = new HashMap<Integer, Integer>(); public void add(int number) { if (elements.containsKey(number)) { elements.put(number, elements.get(number) + 1); } else { elements.put(number, 1); } } public boolean find(int value) { for (Integer i : elements.keySet()) { int target = value - i; if (elements.containsKey(target)) { if (i == target && elements.get(target) < 2) { continue; } return true; } } return false; } }

 

以上是关于170. Two Sum III - Data structure design的主要内容,如果未能解决你的问题,请参考以下文章

170. Two Sum III - Data structure design

[LC] 170. Two Sum III - Data structure design

170. Two Sum III - Data structure design

LeetCode Two Sum III - Data structure design

Two sum III-data structure design

LeetCode-Two Sum III - Data structure design