From 2692e2f6656704172be3111ca442ed6b1df8b4fb Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 22 Jun 2025 19:38:24 +0900 Subject: [PATCH 1/5] Solve : Meeting Rooms --- meeting-rooms/printjin-gmailcom,.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 meeting-rooms/printjin-gmailcom,.py diff --git a/meeting-rooms/printjin-gmailcom,.py b/meeting-rooms/printjin-gmailcom,.py new file mode 100644 index 000000000..34ef1efdc --- /dev/null +++ b/meeting-rooms/printjin-gmailcom,.py @@ -0,0 +1,9 @@ +from typing import List + +class Solution: + def canAttendMeetings(self, intervals: List[Interval]) -> bool: + intervals.sort(key=lambda x: x.start) + for i in range(1, len(intervals)): + if intervals[i].start < intervals[i - 1].end: + return False + return True From 9af2c94fe9df7fd7af891531ca14a5c933f90723 Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 22 Jun 2025 19:50:07 +0900 Subject: [PATCH 2/5] Solve : Lowest Common Ancestor of a Binary Search Tree --- .../printjin-gmailcom.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 lowest-common-ancestor-of-a-binary-search-tree/printjin-gmailcom.py diff --git a/lowest-common-ancestor-of-a-binary-search-tree/printjin-gmailcom.py b/lowest-common-ancestor-of-a-binary-search-tree/printjin-gmailcom.py new file mode 100644 index 000000000..06a0fc5ab --- /dev/null +++ b/lowest-common-ancestor-of-a-binary-search-tree/printjin-gmailcom.py @@ -0,0 +1,9 @@ +class Solution: + def lowestCommonAncestor(self, root, p, q): + while root: + if p.val < root.val and q.val < root.val: + root = root.left + elif p.val > root.val and q.val > root.val: + root = root.right + else: + return root From 68d061cda4b667c1f010f317d355cf55d6b7c786 Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 22 Jun 2025 19:53:31 +0900 Subject: [PATCH 3/5] Solve : Kth Smallest Element In a Bst --- .../printjin-gmailcom.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 kth-smallest-element-in-a-bst/printjin-gmailcom.py diff --git a/kth-smallest-element-in-a-bst/printjin-gmailcom.py b/kth-smallest-element-in-a-bst/printjin-gmailcom.py new file mode 100644 index 000000000..46a757f0c --- /dev/null +++ b/kth-smallest-element-in-a-bst/printjin-gmailcom.py @@ -0,0 +1,15 @@ +class Solution: + def kthSmallest(self, root, k): + self.count = 0 + self.result = 0 + def inorder(node): + if not node: + return + inorder(node.left) + self.count += 1 + if self.count == k: + self.result = node.val + return + inorder(node.right) + inorder(root) + return self.result From 92d9221a592274b99ed3345f1d04d0e5d67cb6d7 Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 22 Jun 2025 19:55:29 +0900 Subject: [PATCH 4/5] Solve : Insert Interval --- insert-interval/printjin-gmailcom.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 insert-interval/printjin-gmailcom.py diff --git a/insert-interval/printjin-gmailcom.py b/insert-interval/printjin-gmailcom.py new file mode 100644 index 000000000..288e32063 --- /dev/null +++ b/insert-interval/printjin-gmailcom.py @@ -0,0 +1,17 @@ +class Solution: + def insert(self, intervals, newInterval): + result = [] + i = 0 + n = len(intervals) + while i < n and intervals[i][1] < newInterval[0]: + result.append(intervals[i]) + i += 1 + while i < n and intervals[i][0] <= newInterval[1]: + newInterval[0] = min(newInterval[0], intervals[i][0]) + newInterval[1] = max(newInterval[1], intervals[i][1]) + i += 1 + result.append(newInterval) + while i < n: + result.append(intervals[i]) + i += 1 + return result From cb9dd7bc7a0207054deff4e95b0f05d5e82610c9 Mon Sep 17 00:00:00 2001 From: printjin Date: Sun, 22 Jun 2025 19:58:09 +0900 Subject: [PATCH 5/5] Solve : Find Median From Data Stream --- find-median-from-data-stream/printjin-gmailcom.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 find-median-from-data-stream/printjin-gmailcom.py diff --git a/find-median-from-data-stream/printjin-gmailcom.py b/find-median-from-data-stream/printjin-gmailcom.py new file mode 100644 index 000000000..2baac7c19 --- /dev/null +++ b/find-median-from-data-stream/printjin-gmailcom.py @@ -0,0 +1,15 @@ +import heapq + +class MedianFinder: + def __init__(self): + self.low = [] + self.high = [] + def addNum(self, num): + heapq.heappush(self.low, -num) + heapq.heappush(self.high, -heapq.heappop(self.low)) + if len(self.high) > len(self.low): + heapq.heappush(self.low, -heapq.heappop(self.high)) + def findMedian(self): + if len(self.low) > len(self.high): + return -self.low[0] + return (-self.low[0] + self.high[0]) / 2