📜  反向链接列表javascript代码示例

📅  最后修改于: 2022-03-11 15:02:47.603000             🧑  作者: Mango

代码示例1
// O(n) time & O(n) space
function reverse(head) {
  if (!head || !head.next) {
    return head;
  }
  let tmp = reverse(head.next);
  head.next.next = head;
  head.next = undefined;
  return tmp;
}