I think there is something wrong with Golang test environment


  • 0
    D

    The Submission Details says: 224 / 225 test cases passed.

    However, when the input is [], my output is null, while the expected is []. I don't know why my output is "null"

    p.s: If you like solving problems in golang, you may take a look at my github repository daoran/leetcode. Please join me solve all problems in golang! : )

    My solution is as follows:

    func flatten(root *TreeNode) {
        if root == nil {
            return
        }
        
    	v := []*TreeNode{}
    	stack := []*TreeNode{}
    
    	node := new(TreeNode)
    	stack = append(stack, root)
    
    	for len(stack) > 0 {
    		node, stack = stack[len(stack)-1], stack[:len(stack)-1]
    		v = append(v, node)
    
    		if node != nil && node.Right != nil {
    			stack = append(stack, node.Right)
    		}
    		if node != nil && node.Left != nil {
    			stack = append(stack, node.Left)
    		}
    
    	}
    
    	v = append(v, nil)
    	for i := 0; i < len(v); i++ {
    		if v[i] != nil {
    			v[i].Left = nil
    			v[i].Right = v[i+1]
    		}
    	}
    
    }
    

  • 0

    Thanks for your tips, and this bug is fixed now.


Log in to reply
 

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