1. 程式人生 > >[LeetCode] Invert Binary Tree 翻轉二叉樹

[LeetCode] Invert Binary Tree 翻轉二叉樹

Invert a binary tree.

在這裡插入圖片描述

// Recursion
class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {
        if (!root) return NULL;
        TreeNode *tmp = root->left;
        root->left = invertTree(root->right);
        root->right = invertTree(tmp);
        return root;
    }
};