Guest User

Untitled

a guest
Jun 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. /**
  2. * Definition for singly-linked list.
  3. * struct ListNode {
  4. * int val;
  5. * ListNode *next;
  6. * ListNode(int x) : val(x), next(NULL) {}
  7. * };
  8. */
  9.  
  10. class Solution {
  11. public:
  12. ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
  13. ListNode dummy(INT_MIN);
  14. ListNode *tail = &dummy;
  15.  
  16. while (l1 && l2) {// while l1!= NULL && l2 != NULL)
  17. if (l1->val < l2->val) {
  18. tail->next = l1;
  19. l1 = l1->next;
  20. } else {
  21. tail->next = l2;
  22. l2 = l2->next;
  23. }
  24. tail = tail->next;
  25. }
  26.  
  27. tail->next = l1 ? l1 : l2;
  28. return dummy.next;
  29. }
  30.  
  31. ListNode *tail = new ListNode()
  32.  
  33. ListNode *tail = new ListNode(int)?
Add Comment
Please, Sign In to add comment