You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); scan.nextLine(); HashSet<String> pairs = new HashSet<>(); int numUnique = 0; for (int i = 0; i < n; i++) { String line = scan.nextLine(); if (!pairs.contains(line)) { numUnique++; pairs.add(line); } System.out.println(numUnique); } scan.close(); } }
Hi guys. This is my solution but it is failing on the 5th test case. Could anyone tell me where I am going wrong?
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 →
Hi guys. This is my solution but it is failing on the 5th test case. Could anyone tell me where I am going wrong?