Skip to content
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
9 changes: 9 additions & 0 deletions merge-intervals/hu6r1s.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution:
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
result = []
for interval in sorted(intervals):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런식으로 정렬된 intervals 변수를 만들지않고 바로 하는 방법도 있다는 걸 배워갑니다!

if not result or result[-1][1] < interval[0]:
result.append(interval)
else:
result[-1][1] = max(result[-1][1], interval[1])
return result
6 changes: 6 additions & 0 deletions missing-number/hu6r1s.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Solution:
def missingNumber(self, nums: List[int]) -> int:
for i in range(len(nums)):
if i not in nums:
return i
return len(nums)
26 changes: 26 additions & 0 deletions reorder-list/hu6r1s.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def reorderList(self, head: Optional[ListNode]) -> None:
"""
Do not return anything, modify head in-place instead.
"""
stack = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stack을 이용한 풀이는 신선하네요 배워갑니다

node = head
while node:
stack.append(node)
node = node.next

node = dummy = ListNode(-1)
for i in range(len(stack)):
if i % 2:
node.next = stack.pop()
else:
node.next = head
head = head.next
node = node.next
node.next = None
return dummy.next