Skip to content

Commit

Permalink
[Binary Search Tree] [enum] Fix height.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanskorb committed May 11, 2018
1 parent 898db6f commit 65e3d4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Binary Search Tree/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ This implementation is recursive, and each case of the enum will be treated diff

public var height: Int {
switch self {
case .Empty: return 0
case .Leaf: return 1
case .Empty: return -1
case .Leaf: return 0
case let .Node(left, _, right): return 1 + max(left.height, right.height)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Binary Search Tree/Solution 2/BinarySearchTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public enum BinarySearchTree<T: Comparable> {
/* Distance of this node to its lowest leaf. Performance: O(n). */
public var height: Int {
switch self {
case .empty: return 0
case .leaf: return 1
case .empty: return -1
case .leaf: return 0
case let .node(left, _, right): return 1 + max(left.height, right.height)
}
}
Expand Down

0 comments on commit 65e3d4d

Please sign in to comment.