xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

LeetCode 重排链表算法题解 All In One

LeetCode 重排链表算法题解 All In One

js / ts 实现重排链表

重排链表原理 图解


/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

/**
 Do not return anything, modify head in-place instead.
 */
function reorderList(head: ListNode | null): void {
  // 方法二:寻找链表中点 + 链表逆序(反转链表) + 合并链表
  // 1. 中点,分隔左右链表
  // 2. 反转右边链表
  // 3. 合并左右链表
};

function findMiddleNode(head: ListNode | null): ListNode | null {
  // 链表的中间结点 (快慢指针)
  return head;
}

function mergeList(list1: ListNode | null, list2: ListNode | null): void {
  // 合并链表
}

function reverseList(head: ListNode | null): ListNode | null {
  // 反转链表 (ES6 swap)
  return head;
}


  1. 重排链表

https://leetcode.com/problems/reorder-list/
https://leetcode.cn/problems/reorder-list/

LeetCode 题解 / LeetCode Solutions

https://www.youtube.com/results?search_query=+Leetcode+143

https://www.youtube.com/playlist?list=PLamwFu9yMruCBtS2tHUD77oI_Wsce-syE

YouTube & LeetCode 力扣官方算法题解视频列表

https://github.com/xgqfrms/leetcode/issues/14

https://www.youtube.com/channel/UCftIXZeipv4MTVwmfFphtYw/videos

https://neetcode.io/

https://github.com/neetcode-gh/leetcode/blob/main/javascript/143-Reorder-List.js

https://github.com/neetcode-gh/leetcode/blob/main/typescript/143-Reorder-List.ts

类似问题

LeetCode 206. Reverse Linked List / 反转链表

https://leetcode.com/problems/reverse-linked-list/

LeetCode 92. Reverse Linked List II / 反转链表 2

https://leetcode.com/problems/reverse-linked-list-ii/

refs

https://www.cnblogs.com/xgqfrms/tag/链表/

https://www.cnblogs.com/xgqfrms/tag/算法题解/



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-08-24 21:43  xgqfrms  阅读(26)  评论(3编辑  收藏  举报