@Hadev
하댑의 개발 기록
@Hadev
전체 방문자
오늘
어제
  • All categories (65)
    • 📒 Tech Note (56)
      • Flutter (0)
      • Unity C# (1)
      • 웹 프로그래밍 (12)
      • CS 기본기 뚝딱 (3)
      • 알고리즘 & 자료구조 (10)
      • DB (6)
      • Cloud (10)
      • DevOps (14)
    • 🔖 Story (9)
      • 💻 개발 언저리 공부 (4)
      • ⛵️ 취미 & 팁 (5)
      • 💸 재테크 (0)

인기 글

티스토리

hELLO · Designed By 정상우.
@Hadev
🚀 Hadev Tech Blog
ABOUT
TAG
GUESTBOOK
[LeetCode] 217. Contains Duplicate
📒 Tech Note/알고리즘 & 자료구조

[LeetCode] 217. Contains Duplicate

2022. 8. 24. 22:57

*알고리즘 스터디에 참여하면서 Blind 75 LeetCode Questions 목록에 있는 문제를 풀이합니다. 

문제: https://leetcode.com/problems/contains-duplicate/

 

Contains Duplicate - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

풀이:

class Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:
        # Sol 1 -- O(n)
        # dist = {}
        # for n in nums:
        #     if n in dist:
        #         return True
        #     dist[n] = 1
        # return False

        # Sol 2 -- Sorting O(N(logN))
        # l = len(nums)
        # if l < 2:
        #     return False
        # nums.sort()
        # for i in range(l-1):
        #     if nums[i] == nums[i+1]:
        #         return True
        # return False

        # Sol 3 -- Set Solution 
        numsSet = set(nums)
        if len(nums) == len(numsSet):
            return False
        return True

 

저작자표시 비영리 변경금지 (새창열림)

'📒 Tech Note > 알고리즘 & 자료구조' 카테고리의 다른 글

[LeetCode] 53. Maximum Subarray  (0) 2022.09.03
[LeetCode] 238. Product of Array Except Self  (0) 2022.08.24
[LeetCode] 121. Best Time to Buy and Sell Stock  (0) 2022.08.20
[LeetCode] 1. Two Sum  (0) 2022.08.20
[선형 자료구조] 1. Array  (0) 2022.08.14
    '📒 Tech Note/알고리즘 & 자료구조' 카테고리의 다른 글
    • [LeetCode] 53. Maximum Subarray
    • [LeetCode] 238. Product of Array Except Self
    • [LeetCode] 121. Best Time to Buy and Sell Stock
    • [LeetCode] 1. Two Sum
    @Hadev
    @Hadev

    티스토리툴바