层次遍历的题目C写吐血了,缓一缓再写那种气死人的题目。
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
void reverseroot(struct TreeNode* root){
if(!root) return;
struct TreeNode* temproot=root->left;
root->left=root->right;
root->right=temproot;
reverseroot(root->left);
reverseroot(root->right);
}
struct TreeNode* invertTree(struct TreeNode* root) {
reverseroot(root);
return root;
}
结果:
标签:right,TreeNode,struct,二叉树,226,left,root,reverseroot,翻转 From: https://www.cnblogs.com/llllmz/p/18054095