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* temp;
- if(l1==nullptr||l2==nullptr)
- {
- temp=nullptr;
- return temp;
- }else
- {
- temp=new ListNode(l1->val);
- temp->next=new ListNode(l2->val);
- temp->next->next=mergeTwoLists(l1->next,l2->next);
- }
- return temp;
- }
- };
Add Comment
Please, Sign In to add comment