Skip to content

Latest commit

 

History

History
86 lines (60 loc) · 1.49 KB

[0170] 两数之和 III - 数据结构设计.md

File metadata and controls

86 lines (60 loc) · 1.49 KB
title tags categories author comments updated permalink mathjax top description date
[0170] 两数之和 III - 数据结构设计
leetcode
leetcode
张学志
true
false
false
false
...
2019-12-31 16:02:50 -0800

题目描述

设计并实现一个 TwoSum 的类,使该类需要支持 add 和 find 的操作。

add 操作 -  对内部数据结构增加一个数。
find 操作 - 寻找内部数据结构中是否存在一对整数,使得两数之和与给定的数相等。

示例 1:

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

示例 2:

add(3); add(1); add(2);
find(3) -> true
find(6) -> false
Related Topics
  • 设计
  • 哈希表
  • 题目代码

    class TwoSum {
    public:
        /** Initialize your data structure here. */
        TwoSum() {
    
        }
        
        /** Add the number to an internal data structure.. */
        void add(int number) {
    
        }
        
        /** Find if there exists any pair of numbers which sum is equal to the value. */
        bool find(int value) {
    
        }
    };
    
    /**
     * Your TwoSum object will be instantiated and called as such:
     * TwoSum* obj = new TwoSum();
     * obj->add(number);
     * bool param_2 = obj->find(value);
     */

    题目解析

    方法一

    方法二

    方法三