blob: e40aaa71eefd6531d32ccf29d6b5506012a205a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// 226. Invert Binary Tree
// given 'root' of binary tree, invert the tree and return its root
#include <stddef.h>
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
};
struct TreeNode *invertTree(struct TreeNode *root) {
struct TreeNode *tmp;
if (root == NULL)
return NULL;
tmp = root->left;
root->left = root->right;
root->right = tmp;
invertTree(root->left);
invertTree(root->right);
return root;
}
|