Golang recursion solution


  • 0
    R
    func rightSideView(root *TreeNode) []int {
        result:= make([]int, 0)
        rightView(root, &result, 0)
        return result
    }
    
    
    func rightView(curr *TreeNode, result *[]int, currDepth int) {
            if curr == nil {
            return
        }
        if currDepth == len(*result) {
            *result = append(*result, curr.Val)
        }
        
        rightView(curr.Right, result, currDepth + 1 )
        rightView(curr.Left, result, currDepth + 1)
    }
    

Log in to reply
 

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