Skip to content

Commit cb3620e

Browse files
authored
Merge pull request #2359 from Alex0M/0958-check-completeness-of-a-binary-tree
Create 0958-check-completeness-of-a-binary-tree.go
2 parents e2d471e + a4c6c70 commit cb3620e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: go/0958-check-completeness-of-a-binary-tree.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
func isCompleteTree(root *TreeNode) bool {
2+
if root == nil {
3+
return true
4+
}
5+
6+
nilNodeFound := false
7+
q := []*TreeNode{root}
8+
9+
for len(q) > 0 {
10+
node := q[0]
11+
q = q[1:]
12+
13+
if node == nil {
14+
nilNodeFound = true
15+
} else {
16+
if nilNodeFound {
17+
return false
18+
}
19+
q = append(q, node.Left)
20+
q = append(q, node.Right)
21+
}
22+
}
23+
return true
24+
}

0 commit comments

Comments
 (0)