[NeetCode/Python] Duplicate Integer

2024. 10. 28. 20:58·Algorithm/NeetCode

문제 링크: https://neetcode.io/problems/duplicate-integer

 

NeetCode

 

neetcode.io

 

내 코드

class Solution:
    def hasDuplicate(self, nums: List[int]) -> bool:
        nums.sort()

        for i in range(1, len(nums)):
            if nums[i] != nums[i-1]:
                continue
            else:
                return True

        return False

 

duplicate가 없어야한다는 말은, 같은 숫자 없이 숫자들이 모두 unique 해야한다는 뜻이다.

어떻게 할까 하다가 정렬해서 옆에 같은 숫자가 있는지만 확인하면 될 것 같아 코드를 이렇게 작성했다.

 

시간 복잡도

O(nlogn)

정렬은 가장 빠른 정렬

 

 

[솔루션]

 

시간 복잡도에 따라 다양한 코드가 작성되어 있어서 조금 놀랐다.

'Algorithm > NeetCode' 카테고리의 다른 글

[NeetCode/Python] Meeting Schedule  (0) 2024.10.02
[NeetCode/Python] Buy and Sell Crypto  (0) 2024.09.19
[NeetCode/Python] Min Cost Climbing Stairs  (0) 2024.09.19
[NeetCode/Python] Kth Largest Integer in a Stream  (0) 2024.09.03
[NeetCode/Python] Two Integer Sum  (0) 2024.08.31
'Algorithm/NeetCode' 카테고리의 다른 글
  • [NeetCode/Python] Meeting Schedule
  • [NeetCode/Python] Buy and Sell Crypto
  • [NeetCode/Python] Min Cost Climbing Stairs
  • [NeetCode/Python] Kth Largest Integer in a Stream
빵빵0
빵빵0
(아직은) 공부하고 정리하는 블로그입니다.
  • 빵빵0
    Hack Your World
    빵빵0
  • 전체
    오늘
    어제
    • 분류 전체보기 (87)
      • Error Handling (7)
      • Project (5)
        • MEV (2)
      • Architecture (0)
        • API (0)
        • Cache (0)
        • 사소한 고민거리 (0)
      • Computer Science (4)
        • Data Structure (2)
        • Database (1)
        • Cloud (0)
        • OS (0)
        • Infra, Network (1)
        • AI (0)
      • Language (7)
        • Go (7)
        • Rust (0)
        • Python (0)
        • Java (0)
      • Algorithm (40)
        • BaekJoon (18)
        • Programmers (7)
        • LeetCode (6)
        • NeetCode (9)
      • SW Books (9)
        • gRPC Up & Running (1)
        • System Design Interview (2)
        • 스프링 입문을 위한 자바 객체지향의 원리와 이해 (6)
        • 블록체인 해설서 (0)
        • 후니의 쉽게 쓴 CISCO 네트워킹 (0)
      • BlockChain (4)
        • Issues (0)
        • Research (4)
        • Tech (0)
      • Own (5)
        • TIR(Today I Read) (0)
        • Personal (2)
        • Novel (0)
        • Memo (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    DP
    BaekJoon
    KBW
    goroutine
    큐
    EVM
    ethereum
    스택
    blockchain
    candlechart
    BEAKJOON
    백준
    Palindrome
    chart
    NeetCode
    go
    2024
    Python
    MongoDB
    Programmers
    two pointer
    context
    프로그래머스
    Hash Table
    블록체인
    MEV
    BFS
    golang
    Greedy
    LeetCode
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.4
빵빵0
[NeetCode/Python] Duplicate Integer
상단으로

티스토리툴바