We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 60f8363 commit 5b56357Copy full SHA for 5b56357
1 file changed
โmerge-two-sorted-lists/Hyeri1ee.javaโ
@@ -0,0 +1,37 @@
1
+import java.util.*;
2
+
3
4
5
6
+class Solution {
7
8
9
+ public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
10
+ ListNode merged = new ListNode();//๋จธ์ง ๋ ๋ ธ๋ ๋ชจ์
11
+ ListNode temp = merged;
12
+ while(list1 != null && list2 != null){
13
14
+ ListNode newNode = new ListNode();//์๋ก์ด ๋ ธ๋
15
+ if (list1.val > list2.val){
16
+ //list2
17
+ newNode.val = list2.val;
18
+ list2 =list2.next;//๋ค์ ๊ฐ๋ฆฌํค๋๋ก\
19
+ // merged.next
20
+ }else{
21
+ newNode.val =list1.val;
22
+ list1=list1.next;//๋ค์ ๊ฐ๋ฆฌํค๋๋ก
23
+ }
24
25
+ merged.next = newNode;
26
+ merged =merged.next;
27
28
29
30
+ if (list1==null)
31
+ merged.next= list2;
32
+ else if (list2 == null)
33
+ merged.next=list1;
34
35
+ return temp.next;
36
37
+}
0 commit comments