leetcode 226 翻转二叉树

public TreeNode invertTree(TreeNode root) {
        if (root == null) return null;
        LinkedList<TreeNode> queue = new LinkedList<>();
        queue.addFirst(root);
        TreeNode t = null;
        while (!queue.isEmpty()){
            TreeNode node = queue.poll();
            t = node.left;
            node.left = node.right;
            node.right = t;
            if (node.left != null) queue.addFirst(node.left);
            if (node.right != null) queue.addFirst(node.right);
        }
        return root;
    }
上一篇:flex布局与position:absolute/fixed冲突问题


下一篇:LeetCode_226.翻转二叉树