We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f1d0427 commit 82f53c3Copy full SHA for 82f53c3
226_invert_binary_tree/invert_binary_tree.c
@@ -10,13 +10,14 @@ struct TreeNode {
10
11
static struct TreeNode *invertTree(struct TreeNode* root)
12
{
13
- if (root != NULL) {
14
- struct TreeNode *node = root->left;
15
- root->left = root->right;
16
- root->right = node;
17
- invertTree(root->left);
18
- invertTree(root->right);
+ if (root == NULL) {
+ return NULL;
19
}
+
+ struct TreeNode *l = invertTree(root->left);
+ struct TreeNode *r = invertTree(root->right);
+ root->left = r;
20
+ root->right = l;
21
return root;
22
23
0 commit comments