My accepted Solution in Golang

  • 0
    func rightSideView(root *TreeNode) []int {
    	var result []int
    	populateRightSideView(root, &result, 0)
    	return result
    func populateRightSideView(root *TreeNode, result *[]int, level int) {
    	if root == nil {
    	if level == len(*result) {
    		*result = append(*result, root.Val)
    	populateRightSideView(root.Right, result, level+1)
    	populateRightSideView(root.Left, result, level+1)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.