File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+
3
+ (n = list1.length + list2.length)
4
+ ์๊ฐ ๋ณต์ก๋: O(n)
5
+ - ์ต์
์ ๊ฒฝ์ฐ ์ ์ฒด ๋
ธ๋ ์ํ
6
+ ๊ณต๊ฐ ๋ณต์ก๋: O(n)
7
+ - ์ต์
์ ๊ฒฝ์ฐ ์ ์ฒด ๋
ธ๋๋งํผ ์ ๋
ธ๋ ์์ฑ
8
+
9
+ */
10
+ class Solution {
11
+ public ListNode mergeTwoLists (ListNode list1 , ListNode list2 ) {
12
+ ListNode head = new ListNode ();
13
+ ListNode curr = head ;
14
+
15
+ while (true ) {
16
+ if (list1 == null ) {
17
+ curr .next = list2 ;
18
+ break ;
19
+ } else if (list2 == null ) {
20
+ curr .next = list1 ;
21
+ break ;
22
+ }
23
+
24
+ if (list1 .val <= list2 .val ) {
25
+ curr .next = new ListNode (list1 .val );
26
+ curr = curr .next ;
27
+ list1 = list1 .next ;
28
+ } else {
29
+ curr .next = new ListNode (list2 .val );
30
+ curr = curr .next ;
31
+ list2 = list2 .next ;
32
+ }
33
+ }
34
+
35
+ return head .next ;
36
+ }
37
+ }
You canโt perform that action at this time.
0 commit comments