dbs ho ja

 avatar
bruteCoder
java
2 months ago
503 B
6
Indexable
Never
	HashSet<Integer> set = new HashSet<>();
		Arraylist<Integer> list = new Arraylist<>();
		for(int i  = 0 ;i<Q;i++){
		    int q = queries[i][0];
		    int val = queries[i][1];
		    
		    if(q== 0) set.add(val);
		    else {
		        if(set.contains(val)){
		            //System.out.println(val);
		            list.add(val);
		            set.remove(val);
		        }else list.add(0);
		    }
		}
		
		int[] out = new int[list.size()];
		int i = 0 ;
		for(int el : list) out[i++] = el;
		return out;
Leave a Comment