今天还在肝大作业,仍然是选了简单题中的简单题,仅维持打卡
一遍过
Num 226 翻转二叉树
/** * 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; if(root->left==NULL && root->right==NULL) return root; TreeNode*temp=new TreeNode(0); temp->left=root->left; root->left=invertTree(root->right); root->right=invertTree(temp->left); return root; } };