leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0021.cpp (473B)
0 class Solution {
1 public:
2 ListNode *mergeTwoLists(ListNode *list1, ListNode *list2) {
3 ListNode head, *t = &head;
5 while (list1 && list2) {
6 if (list1->val < list2->val) {
7 t = t->next = list1;
8 list1 = list1->next;
9 } else {
10 t = t->next = list2;
11 list2 = list2->next;
12 }
13 }
15 t->next = list1 ? list1 : list2;
16 return head.next;
17 }
18 };