leetcode刷题,总结,记录,备忘 101
来源:互联网 发布:java纽约大亨 编辑:程序博客网 时间:2024/06/07 17:47
leetcode101
Symmetric Tree
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 both recursively and iteratively.
confused what "{1,#,2,3}"
means? > read more on how binary tree is serialized on OJ.
/** * 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: bool is(TreeNode * left, TreeNode * right) { if (left == NULL && right == NULL) return true; if (left == NULL && right != NULL) return false; if (left != NULL && right == NULL) return false; if (left->val != right->val) return false; return is(left->left, right->right) && is(left->right, right->left); } bool isSymmetric(TreeNode* root) { if (root == NULL) return true; if (root->left == NULL && root->right == NULL) return true; return is(root->left, root->right); }};
0 0
- leetcode刷题,总结,记录,备忘 101
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- leetcode刷题,总结,记录,备忘83
- leetcode刷题,总结,记录,备忘70
- leetcode刷题,总结,记录,备忘 108
- 一个lwip资料的帖子
- win32+QT 实现exe中执行返回的网页内容重定向到txt文件,根据需求读取里面内容
- STL之map详解
- Windows环境下安装wdl文件
- 编程不过是文字游戏
- leetcode刷题,总结,记录,备忘 101
- (4.1.2.6)Android 判断app是否在前台还是在后台运行
- Java序列化
- bzoj2594水管局长数据加强版题解
- 三行代码实现div内元素垂直居中
- java设计模式之五 —— 单例模式的三种模式优缺点整理
- css控制UL LI 的样式详解(推荐)
- Service_生命周期
- 技能树