美文网首页
226. Invert Binary Tree

226. Invert Binary Tree

作者: becauseyou_90cd | 来源:发表于2018-07-30 21:53 被阅读0次

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;
}

}

相关文章

网友评论

      本文标题:226. Invert Binary Tree

      本文链接:https://www.haomeiwen.com/subject/wceqvftx.html