Skip to content

Commit

Permalink
Merge pull request #827 from limlimjo/main
Browse files Browse the repository at this point in the history
[jj7779607] Week4
  • Loading branch information
SamTheKorean authored Jan 5, 2025
2 parents 8a7472d + 5c235d2 commit 8d48b33
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
29 changes: 29 additions & 0 deletions merge-two-sorted-lists/limlimjo.js
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)
17 changes: 17 additions & 0 deletions missing-number/limlimjo.js
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)

0 comments on commit 8d48b33

Please sign in to comment.