Same Tree [LeetCode]
Problem Description: http://oj.leetcode.com/problems/same-tree/
class Solution {
public:
bool isSameTree(TreeNode *p, TreeNode *q) {
// Note: The Solution object is instantiated only once and is reused by each test case.
if(p == NULL && q == NULL)
return true;
if(p == NULL && q != NULL ||
(p != NULL && q == NULL))
return false;
if(p->val != q->val)
return false;
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
};
Same Tree [LeetCode]的更多相关文章
- Symmetric Tree [LeetCode]
Problem description: http://oj.leetcode.com/problems/symmetric-tree/ Basic idea: Both recursive and ...
- Minimum Depth of Binary Tree ——LeetCode
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- Balanced Binary Tree [LeetCode]
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- Minimum Depth of Binary Tree [LeetCode]
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- 110.Balanced Binary Tree Leetcode解题笔记
110.Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...
- Convert Sorted Array to Binary Search Tree || LeetCode
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * s ...
- Validate Binary Search Tree [LeetCode]
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...
- Recover Binary Search Tree [LeetCode]
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
- Lowest Common Ancestor of a Binary Tree——Leetcode
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...
随机推荐
- Cheatsheet: 2014 01.01 ~ 01.14
.NET 15 reasons why I can't work without JetBrains ReSharper Web Web scraping with Node.js Koa.js : ...
- PHP中的替代语法(冒号、endif、endwhile、endfor)
我们经常在wordpress一类博客程序的模板里面看到很多奇怪的PHP语法,比如: <?php if(empty($GET_['a'])): ?> <font color=" ...
- 502 Proxy Error The proxy server received an invalid response from an upstream server
Proxy Error The proxy server received an invalid response from an upstream server. The proxy server ...
- 配置Servlet3.0的方式和注意事项!
- Hibernate+Struts2+jsp 修改用户信息
在用户列表页面点击修改,进入修改页面 修改薪酬为555,点击提交,重新跳回该页面 修改成功 关键代码如下 基层的代码,这里增加了一个根据用户id查询的方法 dao层 //修改 public USer ...
- [C和指针]第一部分
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 使用escape编码地址栏中的中文字符
在通过地址栏传递参数的时候,有时候会遇到中文参数,在获取这种中文参数值得时候, 往往会出现乱码, 解决办法如下: 在传递参数的使用 escape 函数进行编码,获取的时候再进行解码即可. 例如: va ...
- python_way ,day2 字符串,列表,字典,时间模块
python_way ,day2 字符串,列表,字典,自学时间模块 1.input: 2.0 3.0 区别 2.0中 如果要要用户交互输入字符串: name=raw_input() 如果 name=i ...
- android测试参考,及CreateProcess failure, error问题解决
今天小伙伴问我问题,我给了这2个小命令,或许做android测试的同学可以用得着. 截图命令adb shell /system/bin/screencap -p /sdcard/screenshot. ...
- XAF应用开发教程(五)验证模块
数据验证是应用程序开发中使用频率最高的功能模块,本节详细介绍一下XAF中如何使用验证模块. XAF 验证模块内置了下面的一些验证规则: 验证规则类型 说明 RuleCombinationOfPrope ...