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

Commitf032520

Browse files
refactor 965
1 parenteaac0cb commitf032520

File tree

1 file changed

+16
-51
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+16
-51
lines changed

‎src/main/java/com/fishercoder/solutions/_965.java

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,23 @@
22

33
importcom.fishercoder.common.classes.TreeNode;
44

5-
/**
6-
* 965. Univalued Binary Tree
7-
*
8-
* A binary tree is univalued if every node in the tree has the same value.
9-
*
10-
* Return true if and only if the given tree is univalued.
11-
*
12-
* Example 1:
13-
*
14-
* 1
15-
* / \
16-
* 1 1
17-
* / \ \
18-
* 1 1 1
19-
*
20-
* Input: [1,1,1,1,1,null,1]
21-
* Output: true
22-
*
23-
*
24-
* Example 2:
25-
* 2
26-
* / \
27-
* 2 2
28-
* / \
29-
* 5 2
30-
*
31-
* Input: [2,2,2,5,2]
32-
* Output: false
33-
*
34-
*
35-
* Note:
36-
*
37-
* The number of nodes in the given tree will be in the range [1, 100].
38-
* Each node's value will be an integer in the range [0, 99].
39-
*/
405
publicclass_965 {
41-
publicstaticclassSolution1 {
42-
publicbooleanisUnivalTree(TreeNoderoot) {
43-
if (root ==null) {
44-
returntrue;
45-
}
46-
returndfs(root,root.val);
47-
}
6+
publicstaticclassSolution1 {
7+
publicbooleanisUnivalTree(TreeNoderoot) {
8+
if (root ==null) {
9+
returntrue;
10+
}
11+
returndfs(root,root.val);
12+
}
4813

49-
privatebooleandfs(TreeNoderoot,intvalue) {
50-
if (root ==null) {
51-
returntrue;
52-
}
53-
if (root.val !=value) {
54-
returnfalse;
55-
}
56-
returndfs(root.left,value) &&dfs(root.right,value);
14+
privatebooleandfs(TreeNoderoot,intvalue) {
15+
if (root ==null) {
16+
returntrue;
17+
}
18+
if (root.val !=value) {
19+
returnfalse;
20+
}
21+
returndfs(root.left,value) &&dfs(root.right,value);
22+
}
5723
}
58-
}
5924
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp