ツリーを反転-C++
620 ワード
class Solution {
public:
/**
* @param root: a TreeNode, the root of the binary tree
* @return: nothing
*/
void look(TreeNode *root)
{
if(root==NULL)
return ;
if(root->left==NULL&&root->right==NULL)
return;
TreeNode *x;
x=new TreeNode;
x=root->left;
root->left=root->right;
root->right=x;
look(root->left);
look(root->right);
}
void invertBinaryTree(TreeNode *root) {
look(root);
// write your code here
}
};