Skip to content

Instantly share code, notes, and snippets.

@Mintri1199
Last active May 16, 2019 22:22
Show Gist options
  • Save Mintri1199/242f2592f50d101c948c0a62863076cd to your computer and use it in GitHub Desktop.
Save Mintri1199/242f2592f50d101c948c0a62863076cd to your computer and use it in GitHub Desktop.
class DecimalSearchTree {
...
func contains(numbers: String) -> Bool{
// Return true if this Decimal search tree contains a path at contains
// all the numbers iteratively.
var currentNode: DecimalTreeNode? = self.root
for character in numbers {
let index = Int(String(character))
if let newNode = currentNode?.next[index!] {
currentNode = newNode
} else {
currentNode = nil
break
}
}
return currentNode != nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment