今天完成了力扣最后一道作业,并开始忙碌学生会的各项工作。
226题:翻转二叉树
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: TreeNode* invertTree(TreeNode* root) { if(!root) return root; if(!root->left&&!root->right) return root; TreeNode* t=root->left; root->left=root->right; root->right=t; invertTree(root->left); invertTree(root->right); return root; } };
标签:11,right,TreeNode,val,nullptr,root,left From: https://www.cnblogs.com/jiajiayu/p/17811407.html