Leetcode no. 100
来源:互联网 发布:顶贴软件 编辑:程序博客网 时间:2024/04/28 00:56
100. Same Tree
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. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if (p==null && q==null) return true; else if (p==null || q==null || p.val!= q.val) return false; else if (p.val== q.val) return isSameTree(p.left,q.left) && isSameTree(p.right,q.right); return false; }}
0 0
- Leetcode no. 100
- Leetcode NO.100 Same Tree
- LeetCode--No.100--Same Tree
- LeetCode No.100 Same Tree
- LeetCode No.11 ~No.12
- Leetcode NO.78 Subsets
- Leetcode NO.77 Combinations
- Leetcode NO.46 Permutations
- 【leetcode】No. 235 LCABST
- LeetCode no. 35
- Leetcode no. 37
- Leetcode no. 279
- Leetcode no. 335
- Leetcode no. 283
- Leetcode no. 181 (sql)
- Leetcode no. 40
- Leetcode no. 238
- Leetcode no. 26
- Servlet小记
- codeforces C. Painting Fence
- Log4j使用学习记录
- 关于数字转换为中文大写 的类
- C++之拷贝构造函数
- Leetcode no. 100
- php之SimpleXml操作xml
- 初探CSS与html格式
- 基于webrtc的一对多音视频通讯
- soj 4511 dp差值
- 本地server_ngrok映射ip到外网
- webserve_数据库操作
- finally和exception的思考
- 使用 SDL 过程中遇到的两个问题: 找不到main函数 和 链接错误