aboutsummaryrefslogtreecommitdiffstats
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
parent328 (diff)
downloadleetcode-351af422667c4055bd806065d8bbafbc73facf0e.tar.gz
leetcode-351af422667c4055bd806065d8bbafbc73facf0e.zip
938
Diffstat (limited to '')
-rw-r--r--938/go.mod3
-rw-r--r--938/main.go34
2 files changed, 37 insertions, 0 deletions
diff --git a/938/go.mod b/938/go.mod
new file mode 100644
index 0000000..eb411c6
--- /dev/null
+++ b/938/go.mod
@@ -0,0 +1,3 @@
+module 938
+
+go 1.18
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")
+}