148. Sort List
When doing merge to two lists and don't know the head, we define dummy node = new Node(0), head
, then head = dummy
, return dummy.next
at last.
在合并两个list并且还不知道头节点的时候,我们先定义一个虚拟节点并初始化,和一个当前节点(当前指针),然后让当前指针指向虚拟节点,最后完成合并后返回dummy.next
。
T = O(n lgn), lgn 层调用,每层都做find middle 和 merge需要O(n), S = O(lgn), length of stack.
Last updated