Skip to content

Commit 2b86017

Browse files
authored
Merge pull request #1081 from limlimjo/main
[jj7779607] Week13
2 parents d9d1f59 + b998871 commit 2b86017

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// 시간복잡도: 이진검색트리가 균형잡힌 경우 O(logN), 균형잡히지 않은 경우 O(N)
2+
// 공간복잡도: O(1)
3+
4+
/**
5+
* Definition for a binary tree node.
6+
* function TreeNode(val) {
7+
* this.val = val;
8+
* this.left = this.right = null;
9+
* }
10+
*/
11+
12+
/**
13+
* @param {TreeNode} root
14+
* @param {TreeNode} p
15+
* @param {TreeNode} q
16+
* @return {TreeNode}
17+
*/
18+
var lowestCommonAncestor = function(root, p, q) {
19+
while(root) {
20+
// root의 값보다 p와 q의 값이 모두 작으면 root를 root.left로 이동
21+
if (p.val < root.val && q.val < root.val) {
22+
root = root.left;
23+
}
24+
// root의 값보다 p와 q의 값이 모두 크면 root를 root.right로 이동
25+
else if (p.val > root.val && q.val > root.val) {
26+
root = root.right;
27+
}
28+
else break;
29+
}
30+
return root;
31+
};

meeting-rooms/limlimjo.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// 시간복잡도: O(nlogn)
2+
// 공간복잡도: O(1)
3+
4+
export class Solution {
5+
6+
canAttendMeetings(intervals) {
7+
// Write your code here
8+
intervals.sort((a, b) => a[0] - b[0]);
9+
10+
for (let i = 1; i < intervals.length; i++) {
11+
if (intervals[i][0] < intervals[i - 1][1]) {
12+
return false;
13+
}
14+
}
15+
return true;
16+
}
17+
}
18+

0 commit comments

Comments
 (0)