Skip to main content
Add missing }
Source Link
mjolka
  • 16.3k
  • 2
  • 30
  • 73

Use a Set.

private <E> boolean hasDuplicates(E[] array) {
    Set<E> set = new HashSet<E>();
    for(E e : array) {
        if (!set.add(e)) {
            return true;
        }
    }
    return false; 
}

The add() method of a set returns false if the object already exists in the set.

Use a Set.

private <E> boolean hasDuplicates(E[] array) {
    Set<E> set = new HashSet<E>();
    for(E e : array) {
        if (!set.add(e)) {
            return true;
        }
    return false; 
}

The add() method of a set returns false if the object already exists in the set.

Use a Set.

private <E> boolean hasDuplicates(E[] array) {
    Set<E> set = new HashSet<E>();
    for(E e : array) {
        if (!set.add(e)) {
            return true;
        }
    }
    return false; 
}

The add() method of a set returns false if the object already exists in the set.

Use a Set.

private <E> boolean hasDuplicates(E[] array) {
    Set<E> set = new HashSet<E>();
    for(E e : array) {
        if (!set.add(e)) {
            return true;
        }
    return false; 
}

The add() method of a set returns false if the object already exists in the set.

Use a Set.

private <E> boolean hasDuplicates(E[] array) {
    Set<E> set = new HashSet<E>();
    for(E e : array) {
        if (!set.add(e)) return true;
    }
    return false; 
}

The add method of a set returns false if the object already exists in the set.

Use a Set.

private <E> boolean hasDuplicates(E[] array) {
    Set<E> set = new HashSet<E>();
    for(E e : array) {
        if (!set.add(e)) {
            return true;
        }
    return false; 
}

The add() method of a set returns false if the object already exists in the set.

added 4 characters in body; added 1 character in body; deleted 1 character in body
Source Link

Use a Set.

private <E> boolean hasDuplicates(E[] array) {
    Set<E> set = new HashSet<E>();
    for(E e : array) {
        if (!set.add(e)) return true;
    }
    return false; 
}

The add method of a set returns false if the object already exists in the set.

Use a Set.

private boolean hasDuplicates(E[] array) {
    Set<E> set = new HashSet<E>();
    for(E e : array) {
        if (!set.add(e)) return true;
    }
    return false; 
}

The add method of a set returns false if the object already exists in the set.

Use a Set.

private <E> boolean hasDuplicates(E[] array) {
    Set<E> set = new HashSet<E>();
    for(E e : array) {
        if (!set.add(e)) return true;
    }
    return false; 
}

The add method of a set returns false if the object already exists in the set.

added 166 characters in body
Source Link
Simon Forsberg
  • 59.8k
  • 9
  • 158
  • 312
Loading
Source Link
Loading