File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Definition for singly-linked list.
3+ * function ListNode(val, next) {
4+ * this.val = (val===undefined ? 0 : val)
5+ * this.next = (next===undefined ? null : next)
6+ * }
7+ */
8+ /**
9+ * @param {ListNode } list1
10+ * @param {ListNode } list2
11+ * @return {ListNode }
12+ */
13+ var mergeTwoLists = function ( list1 , list2 ) {
14+ // 리스트가 비었을 때 다른 리스트 반환
15+ if ( list1 === null ) return list2 ;
16+ if ( list2 === null ) return list1 ;
17+
18+ // 작은 값 가진 노드 선택하고 재귀호출
19+ if ( list1 . val <= list2 . val ) {
20+ list1 . next = mergeTwoLists ( list1 . next , list2 ) ;
21+ return list1 ;
22+ } else {
23+ list2 . next = mergeTwoLists ( list1 , list2 . next ) ;
24+ return list2 ;
25+ }
26+ } ;
27+
28+ // 시간 복잡도: O(n1+n2)
29+ // 공간 복잡도: O(1)
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @return {number }
4+ */
5+ var missingNumber = function ( nums ) {
6+ // 1. nums 정렬
7+ nums . sort ( ( a , b ) => a - b ) ;
8+ // 2. for문 돌며 빠진 숫자 찾기
9+ for ( let i = 0 ; i <= nums . length ; i ++ ) {
10+ if ( nums [ i ] !== i ) {
11+ return i ;
12+ }
13+ }
14+ } ;
15+
16+ // 시간 복잡도: O(nlogn)
17+ // 공간 복잡도: O(1)
You can’t perform that action at this time.
0 commit comments