File tree 3 files changed +47
-1
lines changed
3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 47
47
| [ 070] [ 070-question ] | [ Climbing Stairs] [ 070-tips ] | [ ✅] [ 070-java ] | | [ ✅] [ 070-kotlin ] |
48
48
| [ 083] [ 083-question ] | [ Remove Duplicates from Sorted List] [ 083-tips ] | [ ✅] [ 083-java ] | | [ ✅] [ 083-kotlin ] |
49
49
| [ 088] [ 088-question ] | [ Merge Sorted Array] [ 088-tips ] | [ ✅] [ 088-java ] | | [ ✅] [ 088-kotlin ] |
50
- | [ 100] [ 100-question ] | [ Same Tree] [ 100-tips ] | [ ✅] [ 100-java ] | | |
50
+ | [ 100] [ 100-question ] | [ Same Tree] [ 100-tips ] | [ ✅] [ 100-java ] | | [ ✅ ] [ 100-kotlin ] |
51
51
| [ 101] [ 101-question ] | [ Symmetric Tree] [ 101-tips ] | [ ✅] [ 101-java ] | | |
52
52
| [ 104] [ 104-question ] | [ Maximum Depth of Binary Tree] [ 104-tips ] | [ ✅] [ 104-java ] | | |
53
53
| [ 107] [ 107-question ] | [ Binary Tree Level Order Traversal II] [ 107-tips ] | [ ✅] [ 107-java ] | | |
497
497
[ 070-kotlin ] : ./src/_070/kotlin/Solution.kt
498
498
[ 083-kotlin ] : ./src/_083/kotlin/Solution.kt
499
499
[ 088-kotlin ] : ./src/_088/kotlin/Solution.kt
500
+ [ 100-kotlin ] : ./src/_100/kotlin/Solution.kt
500
501
[ 771-kotlin ] : ./src/_771/kotlin/Solution.kt
Original file line number Diff line number Diff line change
1
+ package _100.kotlin
2
+
3
+ import structure.TreeNode
4
+
5
+ /* *
6
+ * @author relish
7
+ * @since 2018/04/25
8
+ */
9
+ /* *
10
+ * Definition for a binary tree node.
11
+ * class TreeNode(var `val`: Int = 0) {
12
+ * var left: TreeNode? = null
13
+ * var right: TreeNode? = null
14
+ * }
15
+ */
16
+ class Solution {
17
+ fun isSameTree (p : TreeNode ? , q : TreeNode ? ): Boolean {
18
+ if (p == null && q == null ) return true
19
+ if (p == null || q == null ) return false
20
+ return p.`val ` == q.`val ` && isSameTree(p.left, q.left) && isSameTree(p.right, q.right)
21
+ }
22
+ }
23
+
24
+ fun main (args : Array <String >) {
25
+ val p = TreeNode (1 )
26
+ p.left = TreeNode (2 )
27
+ p.right = TreeNode (2 )
28
+
29
+ val q = TreeNode (1 )
30
+ q.left = TreeNode (2 )
31
+ q.right = TreeNode (2 )
32
+
33
+ println (Solution ().isSameTree(p, q))
34
+ }
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ Output: false
49
49
50
50
题意是比较两棵二叉树是否相同,那么我们就深搜比较各个节点即可。
51
51
52
+ java:
52
53
``` java
53
54
/**
54
55
* Definition for a binary tree node.
@@ -71,6 +72,16 @@ class Solution {
71
72
}
72
73
```
73
74
75
+ kotlin(184ms/100.00%):
76
+ ``` kotlin
77
+ class Solution {
78
+ fun isSameTree (p : TreeNode ? , q : TreeNode ? ): Boolean {
79
+ if (p == null && q == null ) return true
80
+ if (p == null || q == null ) return false
81
+ return p.`val ` == q.`val ` && isSameTree(p.left, q.left) && isSameTree(p.right, q.right)
82
+ }
83
+ }
84
+ ```
74
85
75
86
## 结语
76
87
You can’t perform that action at this time.
0 commit comments