【Leetcode】Given a binary tree, check whether it is a mirror of itself
来源:互联网 发布:设计效果图软件 编辑:程序博客网 时间:2024/05/21 10:35
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
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: bool isMirrorSame(TreeNode *treea, TreeNode *treeb) { if(!treea && !treeb) return true; if((treea&&!treeb) || (treeb&&!treea)) return false; if(treea->val != treeb->val) return false; return isMirrorSame(treea->left,treeb->right) && isMirrorSame(treea->right,treeb->left); } bool isSymmetric(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(!root) return true; return isMirrorSame(root->left,root->right); }};
- 【Leetcode】Given a binary tree, check whether it is a mirror of itself
- leetCode Given an integer (signed 32 bits), write a function to check whether it is a power of 4
- Check if a given Binary Tree is SumTree
- Check Whether a tree is a BST tree
- 判断是否为完全二叉树 Check whether a binary tree is a complete tree or not
- [LinkedIn] Mirror of a binary tree
- Check whether a string is a palindrome
- Geeks - Check whether a given graph is Bipartite or not 二分图检查
- Check if a binary tree is subtree of another binary tree
- Find whether a given number is a power of 4 or not
- LeetCode Given a binary tree, return the postorder traversal of its nodes' values.
- 1043. Is It a Binary Search Tree
- 1043. Is It a Binary Search Tree
- 1043. Is It a Binary Search Tree
- 1043.Is It a Binary Search Tree
- 1043. Is It a Binary Search Tree
- 1043. Is It a Binary Search Tree
- 1043. Is It a Binary Search Tree
- 【LeetCode】Same Tree --- 二叉树相等
- 黑马程序员 Java基础----IO流(2)
- 内存分配方式,堆区,栈区,new/delete/malloc/free
- Raspberry Pi入门 1——启动
- WIN7下硬盘安装linux双系统教程(EasyBCD法)
- 【Leetcode】Given a binary tree, check whether it is a mirror of itself
- C++四种类型转换
- Hadoop DataNode启动之asyncBlockReport
- ubuntu 10.04.4 安装拼音输入法
- 【数据结构复习】二叉树的遍历——从微软2014校园招聘说起
- uva 709 - Formatting Text(记忆化搜索)
- HDU 3695 Computer Virus on Planet Pandora
- MySQL插入索引太慢,加参数 DELAY_KEY_WRITE
- 堆栈溢出一般是由什么原因导致