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

Commit8fb12cf

Browse files
committed
572
1 parentc2f50ab commit8fb12cf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
defis_subtree(root,sub_root)
2+
returntrueifroot.nil? &&sub_root.nil?
3+
returntrueifsub_root.nil?
4+
returnfalseifroot.nil?
5+
6+
ifsame_tree?(root,sub_root)
7+
true
8+
else
9+
is_subtree(root.left,sub_root) ||
10+
is_subtree(root.right,sub_root)
11+
end
12+
end
13+
14+
defsame_tree?(p,q)
15+
ifp.nil? &&q.nil?
16+
true
17+
elsifp &&q
18+
(p.val ==q.val) &&
19+
same_tree?(p.left,q.left) &&
20+
same_tree?(p.right,q.right)
21+
else
22+
false
23+
end
24+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp