Solution { public int singleNumber(int[] nums) { Map<Integer, List<Integer>> groups = Arrays.stream(nums) .boxed() .collect(Collectors.groupingBy(n -> n)); Optional<Map.Entry<Integer, List<Integer>>> first = groups.entrySet().stream() .filter(entry -> entry.getValue().size() == 1).findFirst(); return first.get().getKey(); }  int singleNumber(int[] nums);  }
@Test public void findInMiddle() throws Exception { Solution solution = new Solution(); int single = solution.singleNumber(new int[]{1, 1, 2, 2, 3, 4, 4, 5, 5}); assertThat(single, is(3)); }