@@ -0,0 +1,1065 @@
+package buildingblock.table.hashing.lc170_twosum3;%0A%0Aimport org.junit.jupiter.api.Assertions;%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * Design and implement a TwoSum class.%0A * It should support the following operations: add and find.%0A */%0Apublic class TwoSum %7B%0A%0A    @Test%0A    void test() %7B%0A        add(1);%0A        Assertions.assertFalse(find(4));%0A        add(3);%0A        add(5);%0A        Assertions.assertTrue(find(4));%0A        Assertions.assertFalse(find(7));%0A        Assertions.assertFalse(find(10));%0A        add(5);%0A        Assertions.assertTrue(find(10));%0A    %7D%0A%0A    private Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A%0A    public void add(int num) %7B%0A        map.put(num, map.getOrDefault(num, 0) + 1);%0A    %7D%0A%0A    // O(N) time%0A    public boolean find(int sum) %7B%0A        for (int num : map.keySet()) %7B%0A            if (map.containsKey(sum - num)) %7B%0A                if (sum != num + num %7C%7C map.get(num) %3E 1) %7B%0A                    return true;%0A                %7D%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%0A%7D%0A

two sum III