linkedlist

package
v0.0.0-...-bced520 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasCycle

func HasCycle(head *ListNode) bool

HasCycle return true if the linked list has a cycle in it.

Types

type ListNode

type ListNode struct {
	Val  int
	Next *ListNode
}

ListNode represents singly-linked list.

func DeleteDuplicates

func DeleteDuplicates(head *ListNode) *ListNode

DeleteDuplicates deletes all duplicates such that each element appears only once. Return the linked list sorted as well

func DeleteDuplicates2

func DeleteDuplicates2(head *ListNode) *ListNode

DeleteDuplicates2 deletes all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as wel

func DetectCycle

func DetectCycle(head *ListNode) *ListNode

DetectCycle returns the node where the cycle begins. If there is no cycle, it returns nil.

func GetIntersectionNode

func GetIntersectionNode(headA, headB *ListNode) *ListNode

func MergeInBetween

func MergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode

MergeInBetween removes nodes that index between a, b in list1, and put list2 in their place.

func NewList

func NewList(vals []int) *ListNode

NewList build a new linked list from array.

func OddEvenList

func OddEvenList(head *ListNode) *ListNode

func Partition

func Partition(head *ListNode, x int) *ListNode

Partition partitions list such that all nodes less than x come before nodes greater than or equal to x.

func RemoveElements

func RemoveElements(head *ListNode, val int) *ListNode

RemoveElements removes elements which value is val from head.

func ReverseBetween

func ReverseBetween(head *ListNode, left int, right int) *ListNode

ReverseBetween reverse the nodes of the list from position left to position right, and return the reversed list

func ReverseList

func ReverseList(head *ListNode) *ListNode

ReverseList reverses the given list.

func SwapPairs

func SwapPairs(head *ListNode) *ListNode

SwapPairs swaps every two adjacent nodes and return its head

func (*ListNode) Equal

func (l *ListNode) Equal(other *ListNode) bool

Equal returns the list l is equal to other.

func (*ListNode) Len

func (l *ListNode) Len() int

Len returns the length of l.

type Node

type Node struct {
	Val    int
	Next   *Node
	Random *Node
}

func CopyRandomList

func CopyRandomList(head *Node) *Node

Jump to

Keyboard shortcuts

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