[NeetCode/Python] Meeting Schedule

2024. 10. 2. 02:21·Algorithm/NeetCode

문제 링크: https://neetcode.io/problems/meeting-schedule

 

NeetCode

 

neetcode.io

 

[내 풀이]

"""
Definition of Interval:
class Interval(object):
    def __init__(self, start, end):
        self.start = start
        self.end = end
"""

class Solution:
    def canAttendMeetings(self, intervals: List[Interval]) -> bool:
        intervals.sort(key=lambda x: x.start)
        
        for i in range(len(intervals) - 1):
            current = intervals[i]
            now = intervals[i + 1]
            
            if current.end > now.start:
                return False
                
        return True

 

intervals 리스트 개수가 500개까지라서 가능한 풀이 같다.

사실 for를 안쓰고 싶었는데 어떻게... 풀 방법이 없더라.

근데 다 풀고 솔루션을 봤는데 나랑 풀이가 똑같아서 안심했다ㅋㅋㅋㅋ

다른점이 있다면 인덱스를 (1, len(intervals))로 두고, i + 1대신 i - 1을 썼다는 점이다. (즉, 이후 값이 아니라 이전 값을 현재 인덱스 값과 비교함)

 

 

시간 복잡도

 O(n)

n은 리스트의 길이

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

[NeetCode/Python] Duplicate Integer  (0) 2024.10.28
[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] Duplicate Integer
  • [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
  • 전체
    오늘
    어제
    • 분류 전체보기 (92)
      • 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 (8)
        • Go (8)
        • 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 (8)
        • TIR(Today I Read) (3)
        • Personal (2)
        • Novel (0)
        • Memo (3)
  • 블로그 메뉴

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

  • 공지사항

  • 인기 글

  • 태그

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

  • 최근 글

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

티스토리툴바