An interesting thing, same code ac for cpp, ce for java


  • 0
    A
    public class Solution {
        public void flatten(TreeNode root) {
            flat(root,null); 
        }
        private TreeNode flat(TreeNode root, TreeNode tail)
        {
            if(root==null) return tail;
            root.right=flat(root->left,flat(root->right,tail));
            root.left=null;
        }
    }
    
    public class Solution {
        public void flatten(TreeNode root) {
            flat(root,null); 
        }
        private TreeNode flat(TreeNode root, TreeNode tail)
        {
            if(root==null) return tail;
            root.right=flat(root.left,flat(root.right,tail));
            root.left=null;
        }
    }
    

    So, why?


  • 0
    L

    Missing the return statement for flat() func.


Log in to reply
 

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