Solution { public boolean containsDuplicate(int[] nums) { if (nums == null || nums.length == 0) { return false; } else { Set<Integer> ints = new HashSet<>(); for (int num : nums) { if (ints.contains(num)) { return true; } ints.add(num); } } return false; }  boolean containsDuplicate(int[] nums);  }
@Test public void emptyArrayNoDups() throws Exception { Solution solution = new Solution(); boolean dups = solution.containsDuplicate(new int[]{}); assertThat(dups, is(false)); }
@Test public void noDupsExample() throws Exception { Solution solution = new Solution(); boolean dups = solution.containsDuplicate(new int[]{1, 2, 3}); assertThat(dups, is(false)); }
@Test public void dupsExample() throws Exception { Solution solution = new Solution(); boolean dups = solution.containsDuplicate(new int[]{1, 2, 3, 1}); assertThat(dups, is(true)); }
@Test public void bigInput() throws Exception { int[] ints = readBigArrayOfInts("bigInput217.properties", "bigArray"); Solution solution = new Solution(); boolean dups = solution.containsDuplicate(ints); assertThat(dups, is(false)); }