LeetCode 226. Invert Binary Tree

来源:互联网 发布:彻底删除windows.old 编辑:程序博客网 时间:2024/05/01 20:29
/** * Definition for a binary tree node. * public class TreeNode { *     int val; *     TreeNode left; *     TreeNode right; *     TreeNode(int x) { val = x; } * } */public class Solution {    public TreeNode invertTree(TreeNode root) {        if (root == null) return null;        TreeNode tmp = root.left;        root.left = root.right;        root.right = tmp;        invertTree(root.left);        invertTree(root.right);        return root;    }}

0 0
原创粉丝点击