Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note:Bonus points if you could solve it b…
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following [1,2,2,null,3,null,3] is not: / \ \ \ Note:Bonus po…
  思路: 主要判断左子树与右子树. 在判断左时,循环下去肯定会到达叶子结点中最左边的结点与最右边的结点比较. 到了这一步因为他们都没有左(右)子树了,所以得开始判断这两个结点的右(左)子树了. 当某个结点对称了,它的左子树也对称了,右子树也对称了,那才是真的对称了. C++ /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode…
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note:Bonus points if you could solve it b…
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric:    1   / \  2   2 / \   / \3  4 4  3 But the following [1,2,2,null,3,null,3] is not:    1   / \ …
给定一个二叉树,检查它是否是它自己的镜像(即,围绕它的中心对称).例如,这个二叉树 [1,2,2,3,4,4,3] 是对称的.    1   / \  2   2 / \ / \3  4 4  3但是下面这个 [1,2,2,null,3,null,3] 则不是:    1   / \  2   2   \   \   3    3说明:如果你可以递归地和迭代地解决它就奖励你点数.详见:https://leetcode.com/problems/symmetric-tree/description…
题目大意 #!/usr/bin/env python # coding=utf-8 # Date: 2018-08-30 """ https://leetcode.com/problems/symmetric-tree/description/ 101. Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). Fo…
Leetcode 101. Symmetric Tree Easy Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following [1,2,2,null,3,nul…
101. Symmetric Tree My Submissions Question Total Accepted: 90196 Total Submissions: 273390 Difficulty: Easy 给定一颗二叉树,检查是否镜像对称(环绕中心对称) Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this bin…
100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL && q == NULL) return true; else if(p == NULL || q == NULL) return false; if(p->val != q->val) return false; return isSameTree(p->left,q->l…