# Leetcode 226. Invert Binary Tree ###### tags: `Leetcode` 題目 Given the root of a binary tree, invert the tree, and return its root. 解法 ``` /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* invertTree(struct TreeNode* root){ 當下節點若是NULL,就直接return if(root == NULL) return NULL; //若不是NULL,就把左右節點做交換 struct TreeNode* temp; temp = root->left; root->left = root->right; root->right = temp; //交換完後,在換成做又節點下面進行交換 invertTree(root->left); invertTree(root->right); return root; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up