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

Commit c0e012e

Browse files
committed
tree pruning
1 parent c117f8d commit c0e012e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎814_binary_tree_pruning.scala‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Solution {
2+
def pruneTree(root: TreeNode): TreeNode = {
3+
if (root == null) null
4+
else{
5+
root.left = pruneTree(root.left)
6+
root.right = pruneTree(root.right)
7+
if (root.value == 0 && root.left == null && root.right == null){
8+
null
9+
}else{
10+
root
11+
}
12+
}
13+
}
14+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /