@@ -0,0 +1,1423 @@
+package com.linbo.algs.leetcode;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * Created by @linbojin on 19/1/17.%0A * Question: https://leetcode.com/problems/two-sum-iii-data-structure-design/%0A */%0Apublic class TwoSumDataStructureDesign %7B%0A%0A  // add O(1), find O(N), space O(N)%0A  private Map%3CInteger, Integer%3E table = new HashMap%3CInteger, Integer%3E();%0A%0A  /** Initialize your data structure here. */%0A  public TwoSumDataStructureDesign() %7B%0A  %7D%0A%0A  /** Add the number to an internal data structure.. */%0A  public void add(int input) %7B%0A    int count = table.containsKey(input) ? table.get(input) : 0;%0A    table.put(input, count + 1);%0A  %7D%0A%0A  /** Find if there exists any pair of numbers which sum is equal to the value. */%0A  public boolean find(int val) %7B%0A    for (Map.Entry%3CInteger, Integer%3E entry : table.entrySet()) %7B%0A      int num = entry.getKey();%0A      int y = val - num;%0A      if (y == num) %7B%0A        // For duplicates, ensure there are at least two individual numbers.%0A        if (entry.getValue() %3E= 2) return true;%0A      %7D else if (table.containsKey(y)) %7B%0A        return true;%0A      %7D%0A    %7D%0A    return false;%0A  %7D%0A%0A  public static void main(String args%5B%5D) %7B%0A    TwoSumDataStructureDesign ts = new TwoSumDataStructureDesign();%0A    ts.add(1);%0A    ts.add(2);%0A    ts.add(3);%0A    ts.add(4);%0A    ts.add(4);%0A%0A    System.out.println(ts.find(6));%0A    System.out.println(ts.find(8));%0A    System.out.println(ts.find(9));%0A  %7D%0A%7D%0A

add TwoSum Data Structure Design implementation