File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * ์๊ฐ ๋ณต์ก๋:
3+ * list1์ ๊ธธ์ด๊ฐ m, list2์ ๊ธธ์ด๊ฐ n์ด๋ฉด
4+ * ํฌ์ธํฐ๊ฐ ์ต๋ m + n๋งํผ ์ํํ๋ฏ๋ก O(m + n)
5+ * ๊ณต๊ฐ ๋ณต์ก๋:
6+ * ํฌ์ธํฐ๋ฅผ ์ฌ์ฉํ๋ฏ๋ก O(1)
7+ */
8+ /**
9+ * Definition for singly-linked list.
10+ * function ListNode(val, next) {
11+ * this.val = (val===undefined ? 0 : val)
12+ * this.next = (next===undefined ? null : next)
13+ * }
14+ */
15+ /**
16+ * @param {ListNode } list1
17+ * @param {ListNode } list2
18+ * @return {ListNode }
19+ */
20+ var mergeTwoLists = function ( list1 , list2 ) {
21+ const head = new ListNode ( 0 , null ) ;
22+ let pointer = head ;
23+ while ( list1 && list2 ) {
24+ if ( list1 . val < list2 . val ) {
25+ pointer . next = list1 ;
26+ list1 = list1 . next ;
27+ } else {
28+ pointer . next = list2 ;
29+ list2 = list2 . next ;
30+ }
31+ pointer = pointer . next ;
32+ }
33+ if ( list1 ) {
34+ pointer . next = list1 ;
35+ } else {
36+ pointer . next = list2 ;
37+ }
38+ return head . next ;
39+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * ์๊ฐ ๋ณต์ก๋: nums.length + 1๋งํผ ์ํํ๋ฏ๋ก O(n)
3+ * ๊ณต๊ฐ ๋ณต์ก๋: totalSum, numsSum ๋ณ์๋ฅผ ์ฌ์ฉํ๋ฏ๋ก O(1)
4+ */
5+ /**
6+ * @param {number[] } nums
7+ * @return {number }
8+ */
9+ var missingNumber = function ( nums ) {
10+ const n = nums . length ;
11+ const totalSum = n * ( n + 1 ) / 2 ;
12+ let numsSum = 0 ;
13+ for ( const n of nums ) {
14+ numsSum += n ;
15+ }
16+ return totalSum - numsSum ;
17+ } ;
You canโt perform that action at this time.
0 commit comments