Answers for "hashset methoids"

0

hashset

/*
 * Template for using hash set to find duplicates.
 */
boolean findDuplicates(List<Type> keys) {
    // Replace Type with actual type of your key
    Set<Type> hashset = new HashSet<>();
    for (Type key : keys) {
        if (hashset.contains(key)) {
            return true;
        }
        hashset.add(key);
    }
    return false;
}
Posted by: Guest on April-06-2022
0

hashset implementation

class MyHashSet {
private:
	vector<bool> table;
public:
	MyHashSet() : table(1e6 + 1, false) {}
	
	void add(int key) {
		table[key] = true;
	}
	
	void remove(int key) {
		table[key] = false;
	}
	
	bool contains(int key) {
		return table[key];
	}
};
Posted by: Guest on April-22-2022

Browse Popular Code Answers by Language