Lonely Integer

  • + 0 comments
    Set<Integer> set = new HashSet<>(a);
            
            Iterator<Integer> it = set.iterator();
            
            int result = 0;
            
            while(it.hasNext()) {
                int next = it.next();
                int fr = Collections.frequency(a, next);
                if (fr == 1) {
                    result = next;
                    break;
                }
            }
            
            return result;