What the problem here


#1

why is the hashset returning duplicates

public class Solution {
    public ArrayList<Interval> merge(ArrayList<Interval> intervals) {
        
        Interval cur=intervals.remove(0);
        HashSet<Interval> ans =new HashSet<>();
        while(intervals.size()>0){
            // if it crosses
            if(cur.end>intervals.get(0).start){
                int min=Math.min(cur.start,intervals.get(0).start);
                int max =Math.max(cur.end,intervals.get(0).end);
                cur = new Interval(min,max);
            }
            // if(!ans.contains(cur)){
                ans.add(cur);
            // }
            intervals.remove(0);
        }
    return new ArrayList<Interval>(ans);
    }
}