Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for a binary tree node.
- * struct TreeNode {
- * int val;
- * struct TreeNode *left;
- * struct TreeNode *right;
- * };
- */
- #define swap_nodes(a, b) \
- ({ \
- a = (((struct TreeNode *) ((uintptr_t) (a) ^ (uintptr_t) (b)))); \
- b = (((struct TreeNode *) ((uintptr_t) (a) ^ (uintptr_t) (b)))); \
- a = (((struct TreeNode *) ((uintptr_t) (a) ^ (uintptr_t) (b)))); \
- })
- struct TreeNode* invertTree(struct TreeNode* root) {
- if (!root)
- return NULL;
- invertTree(root->left);
- invertTree(root->right);
- swap_nodes(root->left, root->right);
- return root;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement