@Test public void singleElem() throws Exception { Solution solution = new Solution(); int single = solution.singleNumber(new int[]{1}); assertThat(single, is(1)); }
public int singleNumber(int[] nums) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i <= nums.length - 1; i++) { int num = nums[i]; if (map.containsKey(num)) { map.put(num, map.get(num) + 1); } else { map.put(num, 1); } } for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (entry.getValue() == 1) { return entry.getKey(); } } return 0; }
Solution { public int singleNumber(int[] nums) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i <= nums.length - 1; i++) { int num = nums[i]; if (map.containsKey(num)) { map.put(num, map.get(num) + 1); } else { map.put(num, 1); } } for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (entry.getValue() == 1) { return entry.getKey(); } } return 0; } }
Solution { public int singleNumber(int[] nums) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i <= nums.length - 1; i++) { int num = nums[i]; if (map.containsKey(num)) { map.put(num, map.get(num) + 1); } else { map.put(num, 1); } } for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (entry.getValue() == 1) { return entry.getKey(); } } return 0; }  }
Solution { public int singleNumber(int[] nums) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i <= nums.length - 1; i++) { int num = nums[i]; if (map.containsKey(num)) { map.put(num, map.get(num) + 1); } else { map.put(num, 1); } } for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (entry.getValue() == 1) { return entry.getKey(); } } return 0; }  int singleNumber(int[] nums); }
Solution { public int singleNumber(int[] nums) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i <= nums.length - 1; i++) { int num = nums[i]; if (map.containsKey(num)) { map.put(num, map.get(num) + 1); } else { map.put(num, 1); } } for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (entry.getValue() == 1) { return entry.getKey(); } } return 0; }  int singleNumber(int[] nums);  }