Two lines by Java 8 Stream:


  • 0
    X
    public boolean containsDuplicate(int[] nums) {
        final Set<Integer> set = new HashSet<>();
        return IntStream.of(nums).anyMatch(i -> set.add(i) == false);
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.