Skip to content

Commit 336cce3

Browse files
committed
Palindromic Substrings - PR 피드백 반영
1 parent 138e4c5 commit 336cce3

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

merge-two-sorted-lists/forest000014.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
1212
ListNode head = new ListNode();
1313
ListNode curr = head;
1414

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-
15+
while (list1 != null && list2 != null) {
2416
if (list1.val <= list2.val) {
2517
curr.next = new ListNode(list1.val);
2618
curr = curr.next;
@@ -32,6 +24,12 @@ public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
3224
}
3325
}
3426

27+
if (list1 == null) {
28+
curr.next = list2;
29+
} else if (list2 == null) {
30+
curr.next = list1;
31+
}
32+
3533
return head.next;
3634
}
3735
}

0 commit comments

Comments
 (0)