From c5e2c82915d2fcd81287843f6b973077646ff896 Mon Sep 17 00:00:00 2001 From: juhui Date: Fri, 6 Feb 2026 17:58:52 +0900 Subject: [PATCH] Solution Week13 --- .../juhui-jeong.java | 18 +++++++++++++ meeting-rooms/juhui-jeong.java | 26 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lowest-common-ancestor-of-a-binary-search-tree/juhui-jeong.java create mode 100644 meeting-rooms/juhui-jeong.java diff --git a/lowest-common-ancestor-of-a-binary-search-tree/juhui-jeong.java b/lowest-common-ancestor-of-a-binary-search-tree/juhui-jeong.java new file mode 100644 index 0000000000..2b6df245ae --- /dev/null +++ b/lowest-common-ancestor-of-a-binary-search-tree/juhui-jeong.java @@ -0,0 +1,18 @@ +/* + 시간복잡도: O(log N) + 공간복잡도: O(1) + */ +class Solution { + public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { + while(root != null) { + if (p.val < root.val && q.val < root.val) { + root = root.left; + } else if (p.val > root.val && q.val > root.val) { + root = root.right; + } else { + return root; + } + } + return null; + } +} diff --git a/meeting-rooms/juhui-jeong.java b/meeting-rooms/juhui-jeong.java new file mode 100644 index 0000000000..35e4368592 --- /dev/null +++ b/meeting-rooms/juhui-jeong.java @@ -0,0 +1,26 @@ +/** + * Definition of Interval: + * public class Interval { + * public int start, end; + * public Interval(int start, int end) { + * this.start = start; + * this.end = end; + * } + * } + */ + +class Solution { + public boolean canAttendMeetings(List intervals) { + intervals.sort((a, b) -> { + if (a.start != b.start) return Integer.compare(a.start, b.start); + return Integer.compare(a.end, b.end); + }); + + for (int i = 1; i < intervals.size(); i++) { + if (intervals.get(i-1).end > intervals.get(i).start) { + return false; + } + } + return true; + } +}