list

package
v0.0.0-...-10bc058 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPalindrome

func IsPalindrome(head *ListNode) bool

没想到什么好的办法,先把链表的节点存入一个 slice,然后双指针从 slice 两头向中间遍历,遇到不同则返回 false,效率很差

func IsPalindromeV2

func IsPalindromeV2(head *ListNode) bool

反转链表后半部分

func TraverseList

func TraverseList(node *ListNode)

遍历一个链表,不改变链表结构

Types

type ListNode

type ListNode struct {
	Val  int
	Next *ListNode
}

func ReverseKGroup

func ReverseKGroup(head *ListNode, k int) *ListNode

func ReverseList

func ReverseList(head *ListNode) *ListNode

注意修改指针指向的值是否会影响到其他变量, 所以需要一个 prev 保存之前的指针,一个 next 保存当前指针的 Next

func ReverseListV2

func ReverseListV2(head *ListNode) *ListNode

对于 ... -> k -> k+1 -> ... ->m 反转 k 的时候,假设 k+1~m 已经反转,则需要把 k+1 的 next 指向 m,k 的 next 指向 nil

Jump to

Keyboard shortcuts

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