-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21.merge-two-sorted-lists.java
41 lines (37 loc) · 1.01 KB
/
21.merge-two-sorted-lists.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// import Parents.ListNode;
// /*
// * @lc app=leetcode id=21 lang=java
// *
// * [21] Merge Two Sorted Lists
// */
// // @lc code=start
// /**
// * Definition for singly-linked list.
// * public class ListNode {
// * int val;
// * ListNode next;
// * ListNode() {}
// * ListNode(int val) { this.val = val; }
// * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
// * }
// */
// class Solution {
// public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
// ListNode ans = new ListNode(-1);
// ListNode temp = ans;
// while (list1 != null || list2 != null) {
// ListNode a = list1,
// b = list2;
// if (a.val < b.val) {
// stemp.next = a;
// temp = temp.next;
// list1 = list1.next;
// }
// else if(a.val==b.val){
// temp.next=a;
// temp.next.next=b;
// }
// }
// }
// }
// // @lc code=end