Package leetcode

Examples of leetcode.TreeNode


public class FlattenBinaryTreeToLinkedList {
    public void flatten(TreeNode root) {
        if (root == null)
            return;
        Stack<TreeNode> stack = new Stack<TreeNode>();
        TreeNode pre = null;
        stack.push(root);

        while (stack.size() > 0) {
            root = stack.pop();
            if (root.right != null)
View Full Code Here


        solve(root.right);
    }

    public static void main(String args[]) {
        Tree2ListNode tl = new Tree2ListNode();
        TreeNode root = new TreeNode(2);
        TreeNode ret = tl.flatten(root);

        for (int i = 0; i < 4; i ++) {
            System.out.println(ret.val);
            ret = ret.right;
        }
View Full Code Here

TOP

Related Classes of leetcode.TreeNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.