cpp solution accepted

  • 0
    class TwoSum {
        unordered_map<int,int> cnt;
        // 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) {
    	    for(auto p:cnt){
    	        if(p.first+p.first!=value && cnt.count(value-p.first)) return true;
    	        else if(p.first+p.first==value && p.second>1) return true;
    	    return false;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.