[leetcode] Invert binary tree.

Posted 白天黑夜每日c

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[leetcode] Invert binary tree.相关的知识,希望对你有一定的参考价值。

Invert a binary tree.

class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {
        TreeNode* temp;
        if(root)
        {
            temp=root->left;
            root->left=root->right;
            root->right=temp;
            if(root->left) invertTree(root->left);
            if(root->right) invertTree(root->right);
        }
        return root;
    }
};

  1. 错:把if用成while。while和递归可以互换

以上是关于[leetcode] Invert binary tree.的主要内容,如果未能解决你的问题,请参考以下文章

#Leetcode# 226. Invert Binary Tree

LeetCode:Invert Binary Tree

Leetcode226:Invert Binary Tree

LeetCode-Invert Binary Tree

[leetcode] Invert binary tree.

Invert Binary Tree --- Python --- LeetCode