Problem
Given an array of integers, find if the array contains any duplicates.
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
Example 1:
Input: [1,2,3,1]
Output: true
Example 2:
Input: [1,2,3,4]
Output: false
Example 3:
Input: [1,1,1,3,3,4,3,2,4,2]
Output: true
-Summary-
1. Compare the length of the original nums list and length of set(nums). If those two length are different, then nums list contains the duplicate number. (Since set does not allow the duplicate number).

모든 문제에 대한 저작권은 LeetCode 회사에 있습니다. [Copyright © 2020 LeetCode]
'LeetCode > Top Interview Q. - Easy' 카테고리의 다른 글
LeetCode 350. Intersection of Two Arrays II (0) | 2020.05.24 |
---|---|
LeetCode 136. Single Number (0) | 2020.05.23 |
LeetCode 122. Best Time to Buy and Sell Stock II (1) | 2020.05.23 |
LeetCode 48. Rotate Image (0) | 2020.05.22 |
LeetCode 283. Move Zeroes (0) | 2020.05.22 |
댓글