util

package
v0.0.0-...-6c0d317 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const (
	NullNode = "null" // 空节点
)

Variables

This section is empty.

Functions

func LeetcodeArrayStringToArray

func LeetcodeArrayStringToArray(array string) []string

Leetcode 代码样例中给的字符串转数组 [0,null,1] => []string{"0", "null", "1"}

func Max

func Max[T lancetconstraints.Number](a, b T) T

return max value

func Repeat

func Repeat(in string, count int) string

func Str2Int

func Str2Int(strs []string) ([]int, error)

func Tree2InOrder

func Tree2InOrder(root *TreeNode) []string

Inorder traversal of binary tree 中序遍历,左右根

func Tree2PostOrder

func Tree2PostOrder(root *TreeNode) []string

Postorder traversal of binary tree 后序遍历,左右根

func Tree2PreOrder

func Tree2PreOrder(root *TreeNode) []string

Preorder traversal of binary tree 前序遍历,根左右

func Tree2Strs

func Tree2Strs(root *TreeNode) []string

二叉树,转leetcode格式的层序数组,按行还原

func TreeSource

func TreeSource(root *TreeNode) []string

由数组构建二叉树,数组是程序遍历的二叉树 如 1_1

    / \
  3_2   2_3
  / \     \
5_4  3_5   9_7

为[1,3,2,5,3,null,9] i*2 i*2+1

0,1,2,3,4, 5,  6

Types

type TreeNode

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

func NewNodeFromString

func NewNodeFromString(str string) (*TreeNode, error)

字符串转二叉树节点

func NewTreeNode

func NewTreeNode(val int) *TreeNode

func Strs2TreeNode

func Strs2TreeNode(strs []string) *TreeNode

字符串数组转二叉树 references:git@github.com:halfrost/LeetCode-Go.git

func (*TreeNode) AddLeft

func (t *TreeNode) AddLeft(node *TreeNode)

func (*TreeNode) AddRight

func (t *TreeNode) AddRight(node *TreeNode)

func (*TreeNode) Depth

func (root *TreeNode) Depth() int

树的最大深度 return the max depth of a tree

func (*TreeNode) PrintHorizontally

func (root *TreeNode) PrintHorizontally() string

display tree like this: * BinaryTree * │ ┌── 6 * │ ┌── 5 * │ ┌── 4 * │ │ └── 3 * └── 2 * └── 1

func (*TreeNode) PrintVertically

func (root *TreeNode) PrintVertically() string

references:https://stackoverflow.com/questions/4965335/how-to-print-binary-tree-diagram-in-java * print tree like this: * 0 * / \ * 1 2

func (*TreeNode) String

func (root *TreeNode) String() string

many ways to print a tree * here print tree [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8] like this: * \---4 * |---1 * | |---0 * | \---2 * | \---3 * \---6 * |---5 * \---7 * \---8

Jump to

Keyboard shortcuts

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