Why did I get MLE?


  • 0
    Y
    public class Solution {
        public void flatten(TreeNode root) {
            //Pre Order
            flatten(root, null);
        }
        public TreeNode flatten(TreeNode root, TreeNode pre){
            if(root==null) return null;
            if(root.left==null && root.right == null){
                //if is leaf node
                root.left = pre;
                return root;
            }
            else if(root.left!=null && root.right == null){
                root.right = root.left;
                root.left = pre;
                return flatten(root.right, root);
            }
            else if(root.left==null && root.right!=null){
                root.left = pre;
                return flatten(root.right,root);
            }else{
                //Intermediate Node
                TreeNode rightNode = root.right;
                root.right = root.left;
                root.left = pre;
                TreeNode leftTree = flatten(root.right, root);
                leftTree.right = rightNode;
                return flatten(rightNode, leftTree);
            }
        }
    }
    

    I've been thinking it all night... why did I get MLE? can anybody help me figure it out?


Log in to reply
 

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