aboutsummaryrefslogtreecommitdiffstats
path: root/783
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2023-02-17 15:39:05 +0000
committerterminaldweller <thabogre@gmail.com>2023-02-17 15:39:05 +0000
commit190bf67e4055f1b612bcd21f19b0acea046ad03a (patch)
treec5b6b4e11eed73ede545074ccd488820989f4c9e /783
parent104 (diff)
downloadleetcode-190bf67e4055f1b612bcd21f19b0acea046ad03a.tar.gz
leetcode-190bf67e4055f1b612bcd21f19b0acea046ad03a.zip
783
Diffstat (limited to '783')
-rw-r--r--783/go.mod3
-rw-r--r--783/main.go47
2 files changed, 50 insertions, 0 deletions
diff --git a/783/go.mod b/783/go.mod
new file mode 100644
index 0000000..14313dc
--- /dev/null
+++ b/783/go.mod
@@ -0,0 +1,3 @@
+module 783
+
+go 1.19
diff --git a/783/main.go b/783/main.go
new file mode 100644
index 0000000..089c86e
--- /dev/null
+++ b/783/main.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "fmt"
+ "math"
+)
+
+type TreeNode struct {
+ Val int
+ Left *TreeNode
+ Right *TreeNode
+}
+
+func min(a, b int) int {
+ if a > b {
+ return b
+ }
+ return a
+}
+
+func walk(node *TreeNode, vals *[]int) {
+ if node == nil {
+ return
+ }
+
+ walk(node.Left, vals)
+ *vals = append(*vals, node.Val)
+ walk(node.Right, vals)
+}
+
+func minDiffInBST(root *TreeNode) int {
+ var vals []int
+
+ walk(root, &vals)
+
+ minDist := math.MaxInt32
+
+ for i := 1; i < len(vals); i++ {
+ minDist = min(minDist, vals[i]-vals[i-1])
+ }
+
+ return minDist
+}
+
+func main() {
+ fmt.Println("vim-go")
+}