标签:思路 tps tree node 题目 solution nod 描述 val binary
翻转一棵二叉树。
递归
/**
* 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* temp=root->left;
root->left=root->right;
root->right=temp;
invertTree(root->left);
invertTree(root->right);
return root;
}
};
标签:思路 tps tree node 题目 solution nod 描述 val binary
原文地址:https://www.cnblogs.com/yjcoding/p/13258669.html