# 170. Two Sum III - Data structure design

**<font color=red>难度: Easy</font>**

## 刷题内容

> 原题连接

* https://leetcode.com/problems/two-sum-iii-data-structure-design/description/

> 内容描述

```
Design and implement a TwoSum class. It should support the following operations: add and find.

add - Add the number to an internal data structure.
find - Find if there exists any pair of numbers which sum is equal to the value.

Example 1:

add(1); add(3); add(5);
find(4) -> true
find(7) -> false
Example 2:

add(3); add(1); add(2);
find(3) -> true
find(6) -> false
```

## 解题方案

> 思路 1
******- 时间复杂度: O(N)******- 空间复杂度: O(N)******

沿用第一题 Two um 的思想，beats 85.71%
```python
class TwoSum(object):

    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.lookup = {}
        self.lst = []

    def add(self, number):
        """
        Add the number to an internal data structure..
        :type number: int
        :rtype: void
        """
        self.lst.append(number)
        self.lookup[number] = self.lookup.get(number, 0) + 1
        

    def find(self, value):
        """
        Find if there exists any pair of numbers which sum is equal to the value.
        :type value: int
        :rtype: bool
        """
        for num in self.lst:
            if value - num in self.lookup:
                if value == 2 * num and self.lookup[num] >= 2:
                    return True
                elif value != 2 * num:
                    return True
    
        return False
        


# Your TwoSum object will be instantiated and called as such:
# obj = TwoSum()
# obj.add(number)
# param_2 = obj.find(value)
```
