From 99c35b25c446694feee71644d0c381cda512d0ef Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA <120540450+ppxyn1@users.noreply.github.com> Date: Sat, 31 Jan 2026 17:18:37 +0900 Subject: [PATCH 1/4] [:solved] #249 --- .../ppxyn1.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lowest-common-ancestor-of-a-binary-search-tree/ppxyn1.py diff --git a/lowest-common-ancestor-of-a-binary-search-tree/ppxyn1.py b/lowest-common-ancestor-of-a-binary-search-tree/ppxyn1.py new file mode 100644 index 0000000000..7357bdeab4 --- /dev/null +++ b/lowest-common-ancestor-of-a-binary-search-tree/ppxyn1.py @@ -0,0 +1,23 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, x): +# self.val = x +# self.left = None +# self.right = None + +# idea: BST property +# Time Complexity : O(long n) +class Solution: + def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': + cur = root + while cur: + if p.val > cur.val and q.val > cur.val: + cur = cur.right + elif p.val < cur.val and q.val < cur.val: + cur = cur.left + else: + return cur + + + + From 570cca07cdf5e6ede8c06fdefe434167f0fdcfc9 Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA <120540450+ppxyn1@users.noreply.github.com> Date: Sun, 1 Feb 2026 15:50:10 +0900 Subject: [PATCH 2/4] [:solved] #252 --- kth-smallest-element-in-a-bst/ppxyn1.py | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 kth-smallest-element-in-a-bst/ppxyn1.py diff --git a/kth-smallest-element-in-a-bst/ppxyn1.py b/kth-smallest-element-in-a-bst/ppxyn1.py new file mode 100644 index 0000000000..9991e54e80 --- /dev/null +++ b/kth-smallest-element-in-a-bst/ppxyn1.py @@ -0,0 +1,31 @@ +# 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 + +#idea : DFS (inorder) +#Time Complexity: O(n) + +class Solution: + def kthSmallest(self, root: Optional[TreeNode], k: int) -> int: + stack = [] + cnt = 0 + curr = root + if not curr: + return + + while curr or stack: + stack.append(curr) + curr = curr.left + curr = stack.pop() + cnt += 1 + + if cnt == k: + return curr.val + + curr = curr.right + + + From 8ad7c1788c42d4c783f3353fb594a8ed980ce57f Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA <120540450+ppxyn1@users.noreply.github.com> Date: Sun, 1 Feb 2026 15:50:51 +0900 Subject: [PATCH 3/4] [:fixed] --- kth-smallest-element-in-a-bst/ppxyn1.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kth-smallest-element-in-a-bst/ppxyn1.py b/kth-smallest-element-in-a-bst/ppxyn1.py index 9991e54e80..0baf399124 100644 --- a/kth-smallest-element-in-a-bst/ppxyn1.py +++ b/kth-smallest-element-in-a-bst/ppxyn1.py @@ -17,6 +17,7 @@ def kthSmallest(self, root: Optional[TreeNode], k: int) -> int: return while curr or stack: + while curr: stack.append(curr) curr = curr.left curr = stack.pop() @@ -27,5 +28,3 @@ def kthSmallest(self, root: Optional[TreeNode], k: int) -> int: curr = curr.right - - From dc292452a930f05e5454b88670f43a557032d267 Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA <120540450+ppxyn1@users.noreply.github.com> Date: Fri, 6 Feb 2026 10:01:18 +0900 Subject: [PATCH 4/4] [:solved] #277 --- insert-interval/ppxyn1.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 insert-interval/ppxyn1.py diff --git a/insert-interval/ppxyn1.py b/insert-interval/ppxyn1.py new file mode 100644 index 0000000000..86f123ccd4 --- /dev/null +++ b/insert-interval/ppxyn1.py @@ -0,0 +1,32 @@ +# idea: - +# Time Complexity: O(n) +class Solution: + def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]: + res = [] + + # Ex,. newInterval = [2,5] + for i in range(len(intervals)): + start, end = intervals[i] + + # [2,5] > [1,5] + + # already passed + if end < newInterval[0]: + res.append(intervals[i]) + + # not started yet + # (2) + elif newInterval[1] < start: + res.append(newInterval) # [1,5] + for j in range(i, len(intervals)): + res.append(intervals[j]) + return res + else: + # (1) + # overlapping + newInterval[0] = min(newInterval[0], start) + newInterval[1] = max(newInterval[1], end) + + res.append(newInterval) + return res +