Loading…
Loading…
Given an array of integers, print true if any value appears at least twice, and false if every element is distinct.
Input: 1 2 3 1
Output: true
A set membership check turns this into a single O(n) pass — if the set's size after adding all elements is smaller than the array length, there was a duplicate.
Input (stdin)
Output
Input (stdin)
Output
Sign in to track solved problems and earn XP.