Skip to content

Commit 65e3d4d

Browse files
committed
1 parent 898db6f commit 65e3d4d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Binary Search Tree/README.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,8 @@ This implementation is recursive, and each case of the enum will be treated diff
615615

616616
public var height: Int {
617617
switch self {
618-
case .Empty: return 0
619-
case .Leaf: return 1
618+
case .Empty: return -1
619+
case .Leaf: return 0
620620
case let .Node(left, _, right): return 1 + max(left.height, right.height)
621621
}
622622
}

Binary Search Tree/Solution 2/BinarySearchTree.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public enum BinarySearchTree<T: Comparable> {
2020
/* Distance of this node to its lowest leaf. Performance: O(n). */
2121
public var height: Int {
2222
switch self {
23-
case .empty: return 0
24-
case .leaf: return 1
23+
case .empty: return -1
24+
case .leaf: return 0
2525
case let .node(left, _, right): return 1 + max(left.height, right.height)
2626
}
2727
}

0 commit comments

Comments
 (0)