Pair for HashSet

PHOTO EMBED

Sun Nov 27 2022 14:42:28 GMT+0000 (Coordinated Universal Time)

Saved by @saqlain #java

class Pair{
    int first;
    int second;
    Pair(int first,int second){
        this.first=first;
        this.second=second;
    }
    public boolean equals(Object o) {
        if (o instanceof Pair) {
            Pair p = (Pair)o;
            return p.first == first && p.second == second;
        }
        return false;
    }
    public int hashCode() {
        return new Integer(first).hashCode() * 31 + new Integer(second).hashCode();
    }
}
content_copyCOPY