Contains Duplicate
EasyArrays & Hashing
The problem
Given an array of integers, return true if any value appears at least twice, and false if every element is distinct.
Input: one line of space-separated integers.
Output: print "true" or "false".
Examples
Input:
1 2 3 1
Output:
true
Input:
1 2 3 4
Output:
false
Constraints
1 <= n <= 10^5Show the worked solution
Put the numbers in a set. If the set is smaller than the list, a duplicate existed. Time O(n), space O(n).
nums = list(map(int, input().split()))
print('true' if len(set(nums)) != len(nums) else 'false')