Concise C# DFS Recursive Solution


  • 1
    H

    public class Solution {

    public void Flatten(TreeNode root) {
        if( root == null) return;
        tail = root;
        if(root.left != null){
            Flatten(root.left);
            tail.right = root.right;
            root.right = root.left;
            root.left = null;
        }
        Flatten(tail.right);
    }
    
    private TreeNode tail;
    

    }


Log in to reply
 

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