Contains Duplicate

Given an integer array, return true if any value appears at least twice. Sorting makes equal values adjacent, so a single linear scan can detect duplicates.

Input Format

nums = array of integers

Output Format

true if any duplicate exists

Constraints

  • 0 <= nums.length <= 10^5; -10^9 <= nums[i] <= 10^9

Examples

Example 1:

Input:

nums = [1,2,3,1]

Output:

true

Explanation:

1 appears more than once.

Example 2:

Input:

nums = [1,2,3,4]

Output:

false

Explanation:

All values are distinct.

Loading...
Contains Duplicate