Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for singly-linked list.
- * struct ListNode {
- * int val;
- * ListNode *next;
- * ListNode(int x) : val(x), next(NULL) {}
- * };
- */
- class Solution {
- public:
- ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
- ListNode dummy(INT_MIN);
- ListNode *tail = &dummy;
- while (l1 && l2) {// while l1!= NULL && l2 != NULL)
- if (l1->val < l2->val) {
- tail->next = l1;
- l1 = l1->next;
- } else {
- tail->next = l2;
- l2 = l2->next;
- }
- tail = tail->next;
- }
- tail->next = l1 ? l1 : l2;
- return dummy.next;
- }
- ListNode *tail = new ListNode()
- ListNode *tail = new ListNode(int)?
Add Comment
Please, Sign In to add comment