Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3df7834

Browse files
authored
Create 0872-leaf-similar-trees.kt
1 parentb3d096b commit3df7834

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎kotlin/0872-leaf-similar-trees.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
classSolution {
2+
funleafSimilar(root1:TreeNode?,root2:TreeNode?):Boolean {
3+
4+
fundfs(root:TreeNode?,res:MutableList<Int>) {
5+
root?:return
6+
7+
if (root.left==null&& root.right==null)
8+
res.add(root.`val`)
9+
10+
dfs(root.left, res)
11+
dfs(root.right, res)
12+
}
13+
14+
val res1:MutableList<Int>=mutableListOf()
15+
val res2:MutableList<Int>=mutableListOf()
16+
17+
dfs(root1, res1)
18+
dfs(root2, res2)
19+
20+
return res1== res2
21+
}
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp