Add solution 701

This commit is contained in:
halfrost
2022-01-07 21:21:21 +08:00
parent 5e2df33c54
commit 172d2fc0ae
3 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package leetcode
import "github.com/halfrost/LeetCode-Go/structures"
// TreeNode define
type TreeNode = structures.TreeNode
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func insert(n *TreeNode, val int) *TreeNode {
if n == nil {
return &TreeNode{Val: val}
}
if n.Val < val {
n.Right = insert(n.Right, val)
} else {
n.Left = insert(n.Left, val)
}
return n
}
func insertIntoBST(root *TreeNode, val int) *TreeNode {
return insert(root, val)
}