mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 09:54:57 +08:00
Update solution 0700
This commit is contained in:
@ -1,10 +1,20 @@
|
|||||||
package leetcode
|
package leetcode
|
||||||
|
|
||||||
type TreeNode struct {
|
import (
|
||||||
Val int
|
"github.com/halfrost/LeetCode-Go/structures"
|
||||||
Left *TreeNode
|
)
|
||||||
Right *TreeNode
|
|
||||||
}
|
// TreeNode define
|
||||||
|
type TreeNode = structures.TreeNode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition for a binary tree node.
|
||||||
|
* type TreeNode struct {
|
||||||
|
* Val int
|
||||||
|
* Left *TreeNode
|
||||||
|
* Right *TreeNode
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
func searchBST(root *TreeNode, val int) *TreeNode {
|
func searchBST(root *TreeNode, val int) *TreeNode {
|
||||||
if root == nil {
|
if root == nil {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# [700. Search in a Binary Search Tree](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/)
|
# [700. Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree/)
|
||||||
|
|
||||||
## 题目
|
## 题目
|
||||||
|
|
||||||
@ -38,13 +38,24 @@ Find the node in the BST that the node's value equals val and return the subtree
|
|||||||
## 代码
|
## 代码
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
||||||
package leetcode
|
package leetcode
|
||||||
|
|
||||||
type TreeNode struct {
|
import (
|
||||||
Val int
|
"github.com/halfrost/LeetCode-Go/structures"
|
||||||
Left *TreeNode
|
)
|
||||||
Right *TreeNode
|
|
||||||
}
|
// TreeNode define
|
||||||
|
type TreeNode = structures.TreeNode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition for a binary tree node.
|
||||||
|
* type TreeNode struct {
|
||||||
|
* Val int
|
||||||
|
* Left *TreeNode
|
||||||
|
* Right *TreeNode
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
func searchBST(root *TreeNode, val int) *TreeNode {
|
func searchBST(root *TreeNode, val int) *TreeNode {
|
||||||
if root == nil {
|
if root == nil {
|
||||||
@ -58,4 +69,5 @@ func searchBST(root *TreeNode, val int) *TreeNode {
|
|||||||
return searchBST(root.Left, val)
|
return searchBST(root.Left, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
Reference in New Issue
Block a user