-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
wrongdouble checkdouble check
Description
Recursion + Linked List
- 문제를 제대로 이해하지 못함.
- 재귀함수 개념 + 링드 리스트 개념 확인하기.
let mergeTwoLists = function(l1, l2) {
let fh = new ListNode(-1);
let current = fh;
while(l1 || l2){
if(l2 == null || (l1 !== null && l1.val <= l2.val)){
fh.next = l1;
fh = fh.next;
l1 = l1.next;
} else {
fh.next = l2;
fh = fh.next;
l2 = l2.next;
}
}
return current.next;
};var mergeTwoLists = function (l1, l2) {
if (!l1 || !l2) return l1 || l2;
if (l1.val < l2.val) {
l1.next = mergeTwoLists(l1.next, l2);
return l1;
}
l2.next = mergeTwoLists(l1, l2.next);
return l2;
};Metadata
Metadata
Assignees
Labels
wrongdouble checkdouble check