Skip to content

Commit 6fcd572

Browse files
committed
Add invert a binary tree.
1 parent 892c1d4 commit 6fcd572

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Binary Tree/BinaryTree.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,13 @@ extension BinaryTree {
5353
}
5454
}
5555
}
56+
57+
extension BinaryTree {
58+
func invert() -> BinaryTree {
59+
if case let .Node(left, value, right) = self {
60+
return .Node(right.invert(), value, left.invert())
61+
} else {
62+
return .Empty
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)