You are viewing a single comment's thread. Return to all comments →
Solved case5: //Write your code here HashSet pairs = new HashSet<>();
for (int i = 0; i < t; i++) { // Create unique pair representation String pair = pair_left[i] + " " + pair_right[i]; // Add to HashSet (automatically handles duplicates) // Print current size after each addition String inverse_pair = pair_right[i] + " " + pair_left[i]; if(!pairs.contains(inverse_pair)) pairs.add(pair); System.out.println(pairs.size()); }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Hashset
You are viewing a single comment's thread. Return to all comments →
Solved case5: //Write your code here HashSet pairs = new HashSet<>();