-
Leetcode 217. Contains Duplicate개발/Leetcode 2023. 6. 24. 10:43
https://leetcode.com/problems/contains-duplicate/description/
Contains Duplicate - LeetCode
Can you solve this real interview question? Contains Duplicate - Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1,2,3,1] Output: true Ex
leetcode.com
문제
nums 배열이 주어질 때 중복된 엘레멘트가 하나라도 존재하는 경우 True 그렇지 않은 경우 False를 반환하라
class Solution:def containsDuplicate(self, nums: List[int]) -> bool:return False if len(nums) == len(set(nums)) else True처음에는 list를 만들어 각 원소를 대입하면서 중복체크를 했으나 시간초과가 발생하여 위와같은 코드를 작성함.
'개발 > Leetcode' 카테고리의 다른 글
Leetcode 125. Valid Palindrome (0) 2023.06.24 Leetcode 1232. Check If It Is a Straight Line (0) 2023.06.24 Leetcode 121. Best Time to Buy and Sell Stock (0) 2023.06.24 Leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee (0) 2023.06.22 [Leetcode] 1161. Maximum Level Sum of a Binary Tree (0) 2023.06.15