LeetCode OJ - Symmetric Tree
来源:互联网 发布:2016年的网络流行语 编辑:程序博客网 时间:2024/06/05 15:30
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 isSymmetric(TreeNode *root) { if(root == NULL) return true; return isSym(root->left, root->right); } bool isSym(TreeNode *left, TreeNode *right) { if(left == NULL && right == NULL) return true; if( (left == NULL && right != NULL) || (left != NULL && right == NULL) ) return false; if(left->val != right->val) return false; return isSym(left->left, right->right) && isSym(left->right, right->left); } };
0 0
- LeetCode OJ:Symmetric Tree
- LeetCode OJ - Symmetric Tree
- [LeetCode OJ]Symmetric Tree
- leetcode oj Symmetric Tree
- LeetCode OJ Symmetric Tree
- [LeetCode OJ]Symmetric Tree
- <LeetCode OJ> 101. Symmetric Tree
- 【LeetCode OJ 101】Symmetric Tree
- Leetcode - Tree - Symmetric Tree
- Leetcode - Tree - Symmetric Tree
- LeetCode[Tree]: Symmetric Tree
- [leetcode][tree] Symmetric Tree
- LeetCode OJ 之 Symmetric Tree(对称树)
- LeetCode: Symmetric Tree
- [Leetcode] Symmetric Tree
- LeetCode : Symmetric Tree
- leetcode 13:symmetric tree
- [LeetCode] Symmetric Tree - Recursively
- HDOJ 3336 Count the string KMP
- How to SSH to a VirtualBox guest externally through a host?
- POJ 1201 Intervals (差分约束系统, 贪心+线段树)
- 2013~2014年终总结
- python中各种基础类型的转换,二进制,八进制,十进制,十六进制
- LeetCode OJ - Symmetric Tree
- java string类 基本操作
- CoAP学习笔记——nodeJS node-coap返回JSON数据包
- 【1004】Financial Management (POJ)(水题——求平均值)
- mac命令大全
- C++ 封装只能防止无意识的越权访问
- Elevator
- MyEclipse 8.5整合Git,并在csdn Git上发布项目
- C语言关键字