Example #1
0
bool TwoSum::find_sum(long int target) {
    long int bucket;
    for( auto it = numbers_to_check.begin(); it != numbers_to_check.end(); it++ ) {
	if( numbers.find((*it) - target) == numbers.end() ) { continue; };
	bucket = numbers.bucket( (*it) - target );
	for(auto it_local = numbers.begin(bucket); it_local != numbers.end(bucket); ++it_local) {
	    if ( ( it_local->first + target ) != (*it) ) { continue; }; 
	    if ( it_local->first != target || (it_local->first == target && multi_numbers.find(target) != multi_numbers.end()) ) {
		std::cout << target << " + " << it_local->first << " = " << (*it) << " ( " << target + it_local->first << std::endl;
		numbers_to_check.erase(it);
		return true; 
	    };
	};
    };
    return false;
};