lc148

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

README

148.排序链表

1. 题目描述

给你链表的头结点 head ,请将其按 升序 排列并返回 排序后的链表

示例 1:


输入:head = [4,2,1,3]
输出:[1,2,3,4]

示例 2:


输入:head = [-1,5,3,4,0]
输出:[-1,0,3,4,5]

示例 3:


输入:head = []
输出:[]

提示:

  • 链表中节点的数目在范围 [0, 5 * 10^4]
  • -10^5 <= Node.val <= 10^5

进阶:你可以在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序吗?

标签 链表 双指针 分治 排序 归并排序

2. 解题

1.采用归并排序(自顶向下递归)

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL