From 715e0e06f7e39dd2f8f0d354ef624c85d0b87bf6 Mon Sep 17 00:00:00 2001 From: KyungJin Jung Date: Sat, 12 Sep 2026 18:02:53 +0900 Subject: [PATCH 1/3] 435. Non-overlapping Intervals --- non-overlapping-intervals/okyungjin.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 non-overlapping-intervals/okyungjin.py diff --git a/non-overlapping-intervals/okyungjin.py b/non-overlapping-intervals/okyungjin.py new file mode 100644 index 0000000000..4925f9af0b --- /dev/null +++ b/non-overlapping-intervals/okyungjin.py @@ -0,0 +1,22 @@ +""" +https://leetcode.com/problems/non-overlapping-intervals/ + +Time: O(N) +Space: O(1) +""" +class Solution: + def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: + # 1. end 오름차순 intervals 정렬 + intervals.sort(key=lambda x: x[1]) + + # remove count + count = 0 + last_end = float('-inf') + + for start, end in intervals: + if start >= last_end: # 구간 안 겹침 + last_end = end + else: # 구간 겹침 + count += 1 + + return count From 61e469208e997687888b2551abf0abd2097886df Mon Sep 17 00:00:00 2001 From: KyungJin Jung Date: Sat, 12 Sep 2026 18:30:00 +0900 Subject: [PATCH 2/3] 100. Same Tree --- same-tree/okyungjin.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 same-tree/okyungjin.py diff --git a/same-tree/okyungjin.py b/same-tree/okyungjin.py new file mode 100644 index 0000000000..bb59f630a3 --- /dev/null +++ b/same-tree/okyungjin.py @@ -0,0 +1,35 @@ +""" +https://leetcode.com/problems/same-tree/description/ + +N: min(p노드수, q노드수) +Time: O(N) +Space: O(N) +""" + +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: + queue = deque([(p, q)]) + + while queue: + node_p, node_q = queue.popleft() + + if not node_p and not node_q: + continue + + elif node_p and node_q: + if node_p.val == node_q.val: + queue.append((node_p.left, node_q.left)) + queue.append((node_p.right, node_q.right)) + else: + return False + + else: + return False + + return True From fc04e6aebbe097c769a3a39c77a946a1a5eec382 Mon Sep 17 00:00:00 2001 From: KyungJin Jung Date: Sat, 12 Sep 2026 18:32:11 +0900 Subject: [PATCH 3/3] =?UTF-8?q?435.=20Non-overlapping=20Intervals=20(?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=EB=B3=B5=EC=9E=A1=EB=8F=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- non-overlapping-intervals/okyungjin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/non-overlapping-intervals/okyungjin.py b/non-overlapping-intervals/okyungjin.py index 4925f9af0b..5fc005fb25 100644 --- a/non-overlapping-intervals/okyungjin.py +++ b/non-overlapping-intervals/okyungjin.py @@ -1,12 +1,12 @@ """ https://leetcode.com/problems/non-overlapping-intervals/ -Time: O(N) +Time: O(N log N), intervals 정렬 Space: O(1) """ class Solution: def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: - # 1. end 오름차순 intervals 정렬 + # end 오름차순 intervals 정렬 intervals.sort(key=lambda x: x[1]) # remove count