-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #827 from limlimjo/main
[jj7779607] Week4
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Definition for singly-linked list. | ||
* function ListNode(val, next) { | ||
* this.val = (val===undefined ? 0 : val) | ||
* this.next = (next===undefined ? null : next) | ||
* } | ||
*/ | ||
/** | ||
* @param {ListNode} list1 | ||
* @param {ListNode} list2 | ||
* @return {ListNode} | ||
*/ | ||
var mergeTwoLists = function (list1, list2) { | ||
// 리스트가 비었을 때 다른 리스트 반환 | ||
if (list1 === null) return list2; | ||
if (list2 === null) return list1; | ||
|
||
// 작은 값 가진 노드 선택하고 재귀호출 | ||
if (list1.val <= list2.val) { | ||
list1.next = mergeTwoLists(list1.next, list2); | ||
return list1; | ||
} else { | ||
list2.next = mergeTwoLists(list1, list2.next); | ||
return list2; | ||
} | ||
}; | ||
|
||
// 시간 복잡도: O(n1+n2) | ||
// 공간 복잡도: O(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @param {number[]} nums | ||
* @return {number} | ||
*/ | ||
var missingNumber = function (nums) { | ||
// 1. nums 정렬 | ||
nums.sort((a, b) => a - b); | ||
// 2. for문 돌며 빠진 숫자 찾기 | ||
for (let i = 0; i <= nums.length; i++) { | ||
if (nums[i] !== i) { | ||
return i; | ||
} | ||
} | ||
}; | ||
|
||
// 시간 복잡도: O(nlogn) | ||
// 공간 복잡도: O(1) |