intersection

package
v0.0.0-...-c9f04ce Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

README

NAME

14 - intersection of two singly linked lists

DESCRIPTION

Problem

Find an intersection of two singly linked list, i.e., a common node, shared by both lists:

Example

Input:

[1] -> [2] -+
            |
            v
           [3] -> [4]
            ^
            |
       [5] -+

Output: Node with value 3

SEE ALSO

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	// contains filtered or unexported fields
}

func Find

func Find(a, b *Node) *Node
Example
package main

import (
	"fmt"

	"github.com/skhal/lab/iq/14/intersection"
)

func main() {
	shared := intersection.NewList(1, 2)
	l1 := intersection.NewList(3, 4).Append(shared)
	l2 := intersection.NewList(5).Append(shared)
	node := intersection.Find(l1, l2)
	fmt.Println(node)
}
Output:

[1 2]

func NewList

func NewList(nn ...int) *Node

func (*Node) Append

func (node *Node) Append(tail *Node) *Node

func (*Node) String

func (node *Node) String() string

func (*Node) ToList

func (node *Node) ToList() []int

Jump to

Keyboard shortcuts

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