Gopherville golang solution


  • 0
    E
    func findsmall(root *TreeNode, count *int, val *int) {
        
        if root == nil {
            return 
        } 
        
        /* In-order traversal */
        findsmall(root.Left, count, val)
        
        *count = *count - 1
        if *count == 0 {
            *val = root.Val
            return 
        }
        
        findsmall(root.Right, count, val)
        
    
        return
    }
    
    
    func kthSmallest(root *TreeNode, k int) int {
        retval := -1
        findsmall(root, &k, &retval)
        return retval
    }

Log in to reply
 

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