kit

package
v0.0.0-...-899dd15 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: MIT Imports: 2 Imported by: 685

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NULL = -1 << 63

NULL 方便添加测试数据

Functions

func Interval2Ints

func Interval2Ints(i Interval) []int

Interval2Ints 把 Interval 转换成 整型切片

func IntervalSlice2Intss

func IntervalSlice2Intss(is []Interval) [][]int

IntervalSlice2Intss 把 []Interval 转换成 [][]int

func List2Ints

func List2Ints(head *ListNode) []int

List2Ints convert List to []int

func Points2Intss

func Points2Intss(points []Point) [][]int

Points2Intss 把 []Point 转换成 [][]int

func Tree2Inorder

func Tree2Inorder(root *TreeNode) []int

Tree2Inorder 把 二叉树转换成 inorder 的切片

func Tree2Postorder

func Tree2Postorder(root *TreeNode) []int

Tree2Postorder 把 二叉树 转换成 postorder 的切片

func Tree2Preorder

func Tree2Preorder(root *TreeNode) []int

Tree2Preorder 把 二叉树 转换成 preorder 的切片

func Tree2ints

func Tree2ints(tn *TreeNode) []int

Tree2ints 把 *TreeNode 按照行还原成 []int

Types

type Interval

type Interval struct {
	Start int
	End   int
}

Interval 提供区间表示

func Intss2IntervalSlice

func Intss2IntervalSlice(intss [][]int) []Interval

Intss2IntervalSlice 把 [][]int 转换成 []Interval

type ListNode

type ListNode struct {
	Val  int
	Next *ListNode
}

ListNode 是链接节点 这个不能复制到*_test.go文件中。会导致Travis失败

func Ints2List

func Ints2List(nums []int) *ListNode

Ints2List convert []int to List

func Ints2ListWithCycle

func Ints2ListWithCycle(nums []int, pos int) *ListNode

Ints2ListWithCycle returns a list whose tail point to pos-indexed node head's index is 0 if pos = -1, no cycle

func (*ListNode) GetNodeWith

func (l *ListNode) GetNodeWith(val int) *ListNode

GetNodeWith returns the first node with val

type Master

type Master struct {
	Secret    string
	WordList  []string
	IsInWords map[string]bool
	Count     int
}

Master 是 LeetCode 的结构体

func (*Master) Guess

func (m *Master) Guess(word string) int

Guess word

func (*Master) Update

func (m *Master) Update()

Update 更新了 m.IsInWords

type NestedInteger

type NestedInteger struct {
	Num int
	Ns  []*NestedInteger
}

NestedInteger is the interface that allows for creating nested lists. You should not implement it, or speculate about its implementation

func (*NestedInteger) Add

func (n *NestedInteger) Add(elem NestedInteger)

Add Set this NestedInteger to hold a nested list and adds a nested integer to it.

func (NestedInteger) GetInteger

func (n NestedInteger) GetInteger() int

GetInteger Return the single integer that this NestedInteger holds, if it holds a single integer The result is undefined if this NestedInteger holds a nested list So before calling this method, you should have a check

func (NestedInteger) GetList

func (n NestedInteger) GetList() []*NestedInteger

GetList Return the nested list that this NestedInteger holds, if it holds a nested list The list length is zero if this NestedInteger holds a single integer You can access NestedInteger's List element directly if you want to modify it

func (NestedInteger) IsInteger

func (n NestedInteger) IsInteger() bool

IsInteger Return true if this NestedInteger holds a single integer, rather than a nested list.

func (*NestedInteger) SetInteger

func (n *NestedInteger) SetInteger(value int)

SetInteger Set this NestedInteger to hold a single integer.

type PQ

type PQ []*entry

PQ implements heap.Interface and holds entries.

func (PQ) Len

func (pq PQ) Len() int

func (PQ) Less

func (pq PQ) Less(i, j int) bool

func (*PQ) Pop

func (pq *PQ) Pop() interface{}

Pop 从 pq 中取出最优先的 entry

func (*PQ) Push

func (pq *PQ) Push(x interface{})

Push 往 pq 中放 entry

func (PQ) Swap

func (pq PQ) Swap(i, j int)

type Point

type Point struct {
	X, Y int
}

Point 定义了一个二维坐标点

func Intss2Points

func Intss2Points(points [][]int) []Point

Intss2Points 把 [][]int 转换成 []Point

type Queue

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

Queue 是用于存放 int 的队列

func NewQueue

func NewQueue() *Queue

NewQueue 返回 *kit.Queue

func (*Queue) IsEmpty

func (q *Queue) IsEmpty() bool

IsEmpty 反馈 q 是否为空

func (*Queue) Len

func (q *Queue) Len() int

Len 返回 q 的长度

func (*Queue) Pop

func (q *Queue) Pop() int

Pop 从 q 中取出最先进入队列的值

func (*Queue) Push

func (q *Queue) Push(n int)

Push 把 n 放入队列

type Stack

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

Stack 是用于存放 int 的 栈

func NewStack

func NewStack() *Stack

NewStack 返回 *kit.Stack

func (*Stack) IsEmpty

func (s *Stack) IsEmpty() bool

IsEmpty 反馈 s 是否为空

func (*Stack) Len

func (s *Stack) Len() int

Len 返回 s 的长度

func (*Stack) Pop

func (s *Stack) Pop() int

Pop 从 s 中取出最后放入 栈 的值

func (*Stack) Push

func (s *Stack) Push(n int)

Push 把 n 放入 栈

type TreeNode

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

TreeNode is tree's node

func GetTargetNode

func GetTargetNode(root *TreeNode, target int) *TreeNode

GetTargetNode 返回 Val = target 的 TreeNode root 中一定有 node.Val = target

func InPost2Tree

func InPost2Tree(in, post []int) *TreeNode

InPost2Tree 把 inorder 和 postorder 切片转换成 二叉树

func Ints2TreeNode

func Ints2TreeNode(ints []int) *TreeNode

Ints2TreeNode 利用 []int 生成 *TreeNode

func PreIn2Tree

func PreIn2Tree(pre, in []int) *TreeNode

PreIn2Tree 把 preorder 和 inorder 切片转换成 二叉树

func (*TreeNode) Equal

func (tn *TreeNode) Equal(a *TreeNode) bool

Equal return ture if tn == a

Jump to

Keyboard shortcuts

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