knakul853

Untitled

Jun 15th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. /**
  2. knakul853
  3.  */
  4. class Solution {
  5. public:
  6.     ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
  7.        
  8.         if(!l1)return l2;
  9.         if(!l2)return l1;
  10.         if(l1->val <= l2->val)
  11.         {
  12.             l1->next = mergeTwoLists(l1->next , l2);
  13.             return l1;
  14.         }
  15.         else
  16.         {
  17.             l2->next = mergeTwoLists(l1, l2->next);return l2;
  18.         }
  19.        
  20.        
  21.     }
  22. };
  23.  
  24. class Solution {
  25. public:
  26.     ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
  27.        
  28.         if(!l1)return l2;
  29.         if(!l2)return l1;
  30.         if(l1->val <= l2->val)
  31.         {
  32.             l1->next = mergeTwoLists(l1->next , l2);
  33.             return l1;
  34.         }
  35.         else
  36.         {
  37.             l2->next = mergeTwoLists(l1, l2->next);return l2;
  38.         }
  39.        
  40.        
  41.     }
  42. };
Add Comment
Please, Sign In to add comment