We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Data Structures
- Java Hashset
- Discussions
Java Hashset
Java Hashset
Sort by
recency
|
356 Discussions
|
Please Login in order to post a comment
/@Author : Rehan/ Set hashSet = new HashSet<>();
I think the solution has an error. In set theory, the elements are unordered, i.e. John and Anne are the same pair as Anne and John. According to test case 2, e.g. cases: kg ni and ni kg are two different pairs. In my solution, in test 2 I have 975 different pairs, in their solution there are 990.
If you find an error, let me know. My solution:
import java.util.HashSet; import java.util.Scanner;
public class SetOfSets { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);
}
I've looked through several solutions and I'm quite surprised. If the problem involves handling pairs and they're already split into two arrays, why combine them back into a single string? Instead, there's a more elegant approach using the SimpleEntry class. You can simply use
Set<AbstractMap.SimpleEntry<String, String>> uniquePairs = new HashSet<>();
to handle the pairs directly.
hi guys i think converting the both arrays into string and adding it into a set is much easy process
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); String [] pair_left = new String[t]; String [] pair_right = new String[t];
}
import java.io.; import java.util.;
public class Solution {
}