struct TreeNode* invertTree(struct TreeNode* root) { if ( NULL == root ) { return NULL; } if ( NULL == root->left && NULL == root->right ) { //叶子节点 return root; } //交换左右子节点 struct TreeNode * pTreeNodeTmp = root->left; root->left = root->right; root->right = pTreeNodeTmp; invertTree(root->left); invertTree(root->right); return root; }
时间: 2024-11-10 01:26:04