-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSameTree.kt
More file actions
24 lines (21 loc) · 807 Bytes
/
SameTree.kt
File metadata and controls
24 lines (21 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package questions
import _utils.UseCommentAsDocumentation
import questions.common.TreeNode
import kotlin.test.assertFalse
import kotlin.test.assertTrue
/**
*
* Given the roots of two binary trees p and q, write a function to check if they are the same or not.
*
* [Source](https://leetcode.com/problems/same-tree/)
*/
@UseCommentAsDocumentation
private fun isSameTree(p: TreeNode?, q: TreeNode?): Boolean {
return TreeNode.isSameAs(p, q)
}
fun main() {
assertFalse(isSameTree(p = TreeNode.from(0), q = TreeNode.from(1)))
assertTrue(isSameTree(p = TreeNode.from(1, 2, 3), q = TreeNode.from(1, 2, 3)))
assertFalse(isSameTree(p = TreeNode.from(1, 2), q = TreeNode.from(arrayOf(1, null, 2))))
assertFalse(isSameTree(p = TreeNode.from(1, 2, 1), q = TreeNode.from(arrayOf(1, 1, 2))))
}