###### "Symmetric Tree" and "Remove Element"

Symmetric Tree:

//一开始用了中序遍历树，检查输出数组是否对称的方法，上传代码后juage错误。
class Solution {
public:
vector<int> temp;
bool isSymmetric(TreeNode* root) {
if (root == NULL)
return true;
middle_order(root);
auto _1_it = temp.begin();
auto _2_it = temp.end() - 1;

for (; _2_it > _1_it; _1_it++, _2_it--)
{
if (*_1_it != *_2_it)
return false;
}
return true;
}
void middle_order(TreeNode* root)
{
if (root != NULL)
{
middle_order(root->left);
temp.push_back(root->val);
middle_order(root->right);
}
}
};

class Solution {
public:
bool isSymmetric(TreeNode* root)
{

if (root == NULL) return true;

return ifSymmetric(root->left, root->right);
}

bool ifSymmetric(TreeNode* tree1, TreeNode* tree2)
{
if (tree1 == NULL && tree2 == NULL)
return true;
if (tree1 == NULL || tree2 == NULL)
return false;

if (tree1->val != tree2->val)
return false;
else
return (ifSymmetric(tree1->left, tree2->right) && ifSymmetric(tree1->right, tree2->left));
}
};

Remove Element:

class Solution {
public:
int removeElement(vector<int>& nums, int val) {

for (auto it = nums.begin(); it != nums.end();)
{
if (*it == val)
it = nums.erase(it);
else
it++;
}
return nums.size();
}
};

#### 【LeetCode】101. Symmetric Tree 解题报告

2016-05-30 23:06:35

#### Lintcode - Remove Node in Binary Search Tree

2015-02-09 11:33:08

#### Symmetric Tree -- LeetCode

2014-04-07 04:52:23

#### LeetCode(101)Symmetric Tree

2014-01-17 06:48:54

#### Leetcode-Symmetric Tree——判断二叉树是否对称

2014-04-20 01:00:22

#### 101. Symmetric Tree [easy] (Python)

2016-06-03 15:53:34

#### 【leetcode c++】101 Symmetric Tree

2015-07-27 14:39:02

#### 101. Symmetric Tree Leetcode Python

2015-01-30 07:28:30

#### 【LeetCode-面试算法经典-Java实现】【101-Symmetric Tree（对称树）】

2015-08-07 07:29:25

#### Leetcode Symmetric Tree 递归和非递归解法

2014-02-16 01:11:36

## 不良信息举报

"Symmetric Tree" and "Remove Element"