Skip to content

Commit c1d6281

Browse files
committed
feat: week4 easy 문제 풀이
1 parent 03ded85 commit c1d6281

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

merge-two-sorted-lists/jinah92.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# O(m+n) times, O(1) spaces
2+
class Solution:
3+
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
4+
dummy = ListNode(None)
5+
node = dummy
6+
7+
while list1 and list2:
8+
if list1.val < list2.val:
9+
node.next = list1
10+
list1 = list1.next
11+
else:
12+
node.next = list2
13+
list2 = list2.next
14+
15+
node = node.next
16+
17+
node.next = list1 or list2
18+
return dummy.next

missing-number/jinah92.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# O(n) times, O(n) spaces
2+
class Solution:
3+
def missingNumber(self, nums: List[int]) -> int:
4+
nums_keys = dict.fromkeys(nums,0)
5+
last = 0
6+
7+
for i in range(len(nums)):
8+
if not i in nums_keys:
9+
return i
10+
last += 1
11+
12+
return last

0 commit comments

Comments
 (0)