intersection

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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