struct ListNode
{
	int val;
	ListNode *next;
	ListNode(int x) : val(x), next(NULL) {}
};
class Solution
{
public:
	ListNode *mergeTwoLists(ListNode *l1, ListNode *l2)
	{
		ListNode h(0, nullptr);
		ListNode *p = &h;
		while (l1 && l2)
		{
			ListNode **t;
			if (l1->val < l2->val)
				t = &l1;
			else
				t = &l2;
			p->next = *t;
			p = *t;
			*t = (*t)->next;
		}
		if (l1)
			p->next = l1;
		else
			p->next = l2;
		return h.next;
	}
};