LeetCode226.翻转二叉树
程序员文章站
2022-05-18 15:41:09
...
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
if(root==NULL) return NULL;
TreeNode* mid=root->left;
root->left=invertTree(root->right);
root->right=invertTree(mid);
return root;
}
};