Skip to content

Latest commit

 

History

History
44 lines (30 loc) · 1.13 KB

_170. Two Sum III - Data structure design.md

File metadata and controls

44 lines (30 loc) · 1.13 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 31, 2024

Last updated : July 31, 2024


Related Topics : Array, Hash Table, Two Pointers, Design, Data Stream

Acceptance Rate : 38.57 %


Solutions

Python

class TwoSum:

    def __init__(self):
        self.vals = Counter()

    def add(self, number: int) -> None:
        self.vals[number] += 1

    def find(self, value: int) -> bool:
        return any(value - val in self.vals 
                   and (val != value - val or self.vals[value - val] > 1) for val in self.vals)

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