aboutsummaryrefslogtreecommitdiffstats
path: root/938/main.go
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-12-07 03:53:52 +0000
committerterminaldweller <thabogre@gmail.com>2022-12-07 03:53:52 +0000
commit351af422667c4055bd806065d8bbafbc73facf0e (patch)
treed9dc1f966339509e89cc6f77f66d714847d3fc56 /938/main.go
parent328 (diff)
downloadleetcode-351af422667c4055bd806065d8bbafbc73facf0e.tar.gz
leetcode-351af422667c4055bd806065d8bbafbc73facf0e.zip
938
Diffstat (limited to '')
-rw-r--r--938/main.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/938/main.go b/938/main.go
new file mode 100644
index 0000000..89c18d3
--- /dev/null
+++ b/938/main.go
@@ -0,0 +1,34 @@
+package main
+
+import "fmt"
+
+type TreeNode struct {
+ Val int
+ Left *TreeNode
+ Right *TreeNode
+}
+
+func preOrder(node *TreeNode, sum *int, low, high int) {
+ if node == nil {
+ return
+ }
+
+ if node.Val >= low && node.Val <= high {
+ *sum += node.Val
+ }
+
+ preOrder(node.Left, sum, low, high)
+ preOrder(node.Right, sum, low, high)
+}
+
+func rangeSumBST(root *TreeNode, low int, high int) int {
+ sum := 0
+
+ preOrder(root, &sum, low, high)
+
+ return sum
+}
+
+func main() {
+ fmt.Println("vim-go")
+}