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

Commitf7fc946

Browse files
same tree
1 parentef23e2b commitf7fc946

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎EASY/src/easy/SameTree.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
packageeasy;
2+
3+
importclasses.TreeNode;
4+
5+
/**100. Same Tree
6+
7+
Total Accepted: 145623
8+
Total Submissions: 330537
9+
Difficulty: Easy
10+
11+
Given two binary trees, write a function to check if they are equal or not.
12+
13+
Two binary trees are considered equal if they are structurally identical and the nodes have the same value. */
14+
publicclassSameTree {
15+
//recursion idea flows out naturally.
16+
publicbooleanisSameTree(TreeNodep,TreeNodeq) {
17+
if(p ==null ||q ==null)returnp ==q;
18+
if(p.val !=q.val)returnfalse;
19+
returnisSameTree(p.left,q.left) &&isSameTree(p.right,q.right);
20+
}
21+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp