MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / dfs

Function dfs

go/0110-balanced-binary-tree.go:18–27  ·  view source on GitHub ↗
(root *TreeNode)

Source from the content-addressed store, hash-verified

16}
17
18func dfs(root *TreeNode) BalanceTree {
19 if root == nil {
20 return BalanceTree{true, 0}
21 }
22
23 left, right := dfs(root.Left), dfs(root.Right)
24 balanced := (left.Balance && right.Balance && int(math.Abs(float64(left.Height)-float64(right.Height))) <= 1)
25
26 return BalanceTree{balanced, 1 + max(left.Height, right.Height)}
27}
28
29func max(a, b int) int {
30 if a > b {

Callers 1

isBalancedFunction · 0.70

Calls 1

maxFunction · 0.70

Tested by

no test coverage detected