标签:sub ret content solution des describe root desc off
二叉树的镜像定义:源二叉树 8 / 6 10 / \ / 5 7 9 11 镜像二叉树 8 / 10 6 / \ / 11 9 7 5
1 /* 2 struct TreeNode { 3 int val; 4 struct TreeNode *left; 5 struct TreeNode *right; 6 TreeNode(int x) : 7 val(x), left(NULL), right(NULL) { 8 } 9 };*/ 10 class Solution { 11 public: 12 void Mirror(TreeNode *pRoot) { 13 if (pRoot==NULL) return; 14 Swap(pRoot); 15 16 if (pRoot->left!=NULL) 17 Mirror(pRoot->left); 18 if (pRoot->right!=NULL) 19 Mirror(pRoot->right); 20 return ; 21 } 22 void Swap(TreeNode *pRoot){ 23 TreeNode *node=pRoot->left; 24 pRoot->left=pRoot->right; 25 pRoot->right=node; 26 return ; 27 } 28 };
标签:sub ret content solution des describe root desc off
原文地址:https://www.cnblogs.com/q1204675546/p/13362567.html