Skip to content

Commit

Permalink
Create 0199-binary-tree-right-side-view.go
Browse files Browse the repository at this point in the history
  • Loading branch information
AP-Repositories authored Jan 1, 2023
1 parent 0cb22b5 commit d731205
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions go/0199-binary-tree-right-side-view.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
func rightSideView(root *TreeNode) []int {
res := make([]int, 0)
q := []*TreeNode{root}

for len(q) != 0 {
var rightSide *TreeNode
qLen := len(q)

for i := 0; i < qLen; i++ {
node := q[0]
q = q[1:]
if node != nil {
rightSide = node
q = append(q, node.Left)
q = append(q, node.Right)
}
}
if rightSide != nil {
res = append(res, rightSide.Val)
}
}
return res
}

0 comments on commit d731205

Please sign in to comment.