Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lcof/面试题27. 二叉树的镜像/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,37 @@ func mirrorTree(root *TreeNode) *TreeNode {
}
```

### **C++**

```cpp
/**
* 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* mirrorTree(TreeNode* root) {
// 后续遍历
if (nullptr == root) {
return nullptr;
}

mirrorTree(root->left);
mirrorTree(root->right);
std::swap(root->left, root->right);

return root;
}
};

```

### **...**

```
Expand Down
26 changes: 26 additions & 0 deletions lcof/面试题27. 二叉树的镜像/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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* mirrorTree(TreeNode* root) {
// 后续遍历
if (nullptr == root) {
return nullptr;
}

mirrorTree(root->left);
mirrorTree(root->right);
std::swap(root->left, root->right);

return root;

}
};
2 changes: 1 addition & 1 deletion lcof/面试题55 - II. 平衡二叉树/Solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Solution {
}
}

return false; // 如果
return false; // 如果有一处已经确定不是平衡二叉树了,则直接返回false
}

bool isBalanced(TreeNode* root) {
Expand Down