Skip to content

Instantly share code, notes, and snippets.

@yairzaslavsky
Last active January 4, 2022 00:39
Show Gist options
  • Save yairzaslavsky/20fb544c0984c6afa1f7ee6090531b2a to your computer and use it in GitHub Desktop.
Save yairzaslavsky/20fb544c0984c6afa1f7ee6090531b2a to your computer and use it in GitHub Desktop.
class TreeNode(var `val`: Int) {
var left: TreeNode? = null
var right: TreeNode? = null
}
fun main(args: Array<String>) {
val root = TreeNode(1).apply {
left = TreeNode(2).apply { // left child of 1
left = TreeNode(4) // left child of 2
}
right = TreeNode(3).apply { // right child of 1
right = TreeNode(5).apply { // right child of 3
left = TreeNode(6) // left child of 5
right = TreeNode(7) // right child of 5
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment