Skip to content

Commit 1c42189

Browse files
authored
Fix: Remove accidentally duplicated code block
1 parent cf23f1e commit 1c42189

File tree

1 file changed

+0
-46
lines changed

1 file changed

+0
-46
lines changed

โ€Žmerge-two-sorted-lists/river20s.javaโ€Ž

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,4 @@ public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
4444
return rs.next;
4545
}
4646
}
47-
/**
48-
* Definition for singly-linked list.
49-
* public class ListNode {
50-
* int val;
51-
* ListNode next;
52-
* ListNode() {}
53-
* ListNode(int val) { this.val = val; }
54-
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
55-
* }
56-
*/
57-
class Solution {
58-
/*
59-
* [ํ’€์ด]
60-
* 1) ๋‘ ๋ฆฌ์ŠคํŠธ๊ฐ€ ์ด๋ฏธ ์ •๋ ฌ๋œ ์ƒํƒœ โ†’ ๋งจ ์•ž์—์„œ๋ถ€ํ„ฐ ๋‘˜ ์ค‘ ๋” ์ž‘์€ ๋…ธ๋“œ๋ฅผ ๊ฒฐ๊ณผ ๋ฆฌ์ŠคํŠธ rs์— ์ด์–ด ๋ถ™์ธ๋‹ค.
61-
* 2) ํ•˜๋‚˜์˜ ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋๋‚  ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•œ๋‹ค. โ†’ ๋‚จ์€ ๋ฆฌ์ŠคํŠธ์˜ ๋…ธ๋“œ๋Š” ๊ทธ๋Œ€๋กœ rs์— ๋ถ™์ธ๋‹ค.
62-
* 3) rs ํ—ค๋“œ ๋…ธ๋“œ์˜ next๋ถ€ํ„ฐ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
63-
* [T.C]
64-
* ๊ฐ ๋…ธ๋“œ๋ฅผ ํ•œ ๋ฒˆ์”ฉ ๋น„๊ต โ†’ ์—ฐ๊ฒฐ(๋˜๋Š” ์—ฐ๊ฒฐ๋งŒ)ํ•˜๋ฏ€๋กœ,
65-
* T.C = O(n+m) (n = list1์˜ ๊ธธ์ด, m = list2์˜ ๊ธธ์ด)
66-
* [S.C]
67-
* list1๊ณผ list2์˜ ๋…ธ๋“œ๋ฅผ ๋‹ค์‹œ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒƒ์ด๋ฏ€๋กœ ์ถ”๊ฐ€์ ์ธ ๊ณต๊ฐ„์€ ๊ฑฐ์˜ ํ•„์š”ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ(rs์˜ head ์ •๋„?),
68-
* S.C = O(1)
69-
*/
70-
71-
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
72-
ListNode rs = new ListNode(0);
73-
ListNode rsNext = rs;
74-
// step 1
75-
while (list1 != null && list2 != null) {
76-
if (list1.val <= list2.val) {
77-
rsNext.next = list1;
78-
list1 = list1.next;
79-
}
80-
else {
81-
rsNext.next = list2;
82-
list2 = list2.next;
83-
}
84-
rsNext = rsNext.next;
85-
}
86-
// step 2
87-
if (list1 != null) rsNext.next = list1;
88-
if (list2 != null) rsNext.next = list2;
89-
// step3
90-
return rs.next;
91-
}
92-
}
9347

0 commit comments

Comments
ย (0)