Skip to content

[kayden] Week 13 Solutions #582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions house-robber/kayden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
# 시간복잡도: O(N)
# 공간복잡도: O(1)
def rob(self, nums: List[int]) -> int:
one, two = 0, 0

for num in nums:
temp = max(two+num, one)
two, one = one, temp

return one
20 changes: 20 additions & 0 deletions lowest-common-ancestor-of-a-binary-search-tree/kayden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution:
# 시간복잡도: O(N)
# 공간복잡도: O(1)
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
def find(node):
if not node:
return None

left = find(node.left)
right = find(node.right)

if node == p or node == q:
return node

if left and right:
return node

return left or right

return find(root)
14 changes: 14 additions & 0 deletions meeting-rooms/kayden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
# 시간복잡도: O(NlogN)
# 공간복잡도: O(1)
def can_attend_meetings(self, intervals: List[Interval]) -> bool:
intervals.sort()

prev = 0
for start, end in intervals:
if end < prev:
return False

prev = end

return True