https://leetcode.com/problems/invert-binary-tree/description/
解题思路:用preoder traversal解决
代码:
class Solution {
public TreeNode invertTree(TreeNode root) {
if(root == null) return null;
TreeNode temp = root.left;
root.left = invertTree(root.right);
root.right = invertTree(temp);
return root;
}
}
网友评论