Leetcode 100. Same Tree (Easy) (cpp)
2016-07-22 14:48
453 查看
Leetcode 100. Same Tree (Easy) (cpp)
Tag: Tree, Depth-first Search
Difficulty: Easy
Tag: Tree, Depth-first Search
Difficulty: Easy
/* 100. Same Tree (Easy) Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. */ /** * 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 isSameTree(TreeNode* p, TreeNode* q) { if (!p || !q) { if (p || q) return false; return true; } return p -> val == q -> val && isSameTree(p -> left, q -> left) && isSameTree(p -> right, q -> right); } };
相关文章推荐
- 设计模式之状态STATE模式(C++)
- 用C++11的std::async代替线程的创建
- C语言中位移问题
- C++不确定参数个数函数调用
- Leetcode 101. Symmetric Tree (Easy) (cpp)
- c++中pow 与sqrt函数使用指南
- 数组中第K大的数
- max函数|C++返回数组中的最大值——max_element函数
- c++ string 末尾追加char字符
- C语言输出PI和正弦函数和余弦函数
- C++ ABI之名字改编(以Qt为例)
- C++ ABI之名字改编(以Qt为例)
- C++学习笔记——string型 到 int,double,float型的相互转换:ostringsream,istringstream,stringstream
- c语言中结构体的使用
- C++常见问题: 字符串分割函数 split
- Eclispe 阅读C++代码
- protobuf C++入门
- Cpp环境 【poj 2940 】【Uva11054】【Vijos2909】Wine Trading in Gergovia 格尔高维亚的肮脏红酒交易
- C++中嵌入python程序——使用API接口,从函数到类
- C++学习之路(2) C++输入输出 new delete操作符 函数重载