Skip to content

Commit a460d60

Browse files
add java solution for leetcode 100
1 parent 61631e8 commit a460d60

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ LeetCode
301301
|114|[Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list/)| |Medium|
302302
|113|[Path Sum II](https://leetcode.com/problems/path-sum-ii/)| |Medium|
303303
|112|[Path Sum](https://leetcode.com/problems/path-sum/)| |Easy|
304-
|111|[Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/)| [java](./algorithms/balancedBinaryTree/Solution.java) |Easy|
305-
|110|[Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/)| |Easy|
304+
|111|[Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/)| |Easy|
305+
|110|[Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/)| [java](./algorithms/balancedBinaryTree/Solution.java) |Easy|
306306
|109|[Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/)| |Medium|
307307
|108|[Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/)| |Medium|
308308
|107|[Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii/)| |Easy|
@@ -312,7 +312,7 @@ LeetCode
312312
|103|[Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/)| |Medium|
313313
|102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)| |Easy|
314314
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)| [java](./algorithms/sysmetricTree/Solution.java) |Easy|
315-
|100|[Same Tree](https://leetcode.com/problems/same-tree/)| |Easy|
315+
|100|[Same Tree](https://leetcode.com/problems/same-tree/)| [java](./algorithms/sameTree/Solution.java) |Easy|
316316
|99|[Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree/)| |Hard|
317317
|98|[Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/)| |Medium|
318318
|97|[Interleaving String](https://leetcode.com/problems/interleaving-string/)| |Hard|

algorithms/sameTree/Solution.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Solution {
2+
public boolean isSameTree(TreeNode p, TreeNode q) {
3+
// 比较两颗树是否相等,通过对树的遍历比较树的值是否相等
4+
if (null == p && null == q) {
5+
return true;
6+
}
7+
if (null == p && null != q) {
8+
return false;
9+
}
10+
if (null != p && null == q) {
11+
return false;
12+
}
13+
if (p.val != q.val) {
14+
return false;
15+
}
16+
17+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
18+
}
19+
}

0 commit comments

Comments
 (0)