본문 바로가기
LeetCode/Top Interview Q. - Easy

LeetCode 217. Contains Duplicate

by 벤진[Benzene] 2020. 5. 23.

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]

https://leetcode.com/

댓글