Skip to content

Instantly share code, notes, and snippets.

@Mintri1199
Created May 16, 2019 21:51
Show Gist options
  • Save Mintri1199/14148f707140e7ec42fd8a298aaf5832 to your computer and use it in GitHub Desktop.
Save Mintri1199/14148f707140e7ec42fd8a298aaf5832 to your computer and use it in GitHub Desktop.
class DecimalTreeNode {
...
func isLeaf() -> Bool {
// Check if the current node is a leaf or not
// Count the number of nil values in self.next
for item in self.next {
if item != nil { // There is a child of the node
return false
}
}
// The node has no children
return true
}
func isBranch() -> Bool{
// Check if the current node is a branch or not
return !self.isLeaf()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment