2022-01-18 16:17:04 +01:00
|
|
|
/**
|
|
|
|
* Example:
|
|
|
|
* var ti = TreeNode(5)
|
|
|
|
* var v = ti.`val`
|
|
|
|
* Definition for a binary tree node.
|
|
|
|
* class TreeNode(var `val`: Int) {
|
|
|
|
* var left: TreeNode? = null
|
|
|
|
* var right: TreeNode? = null
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
class Solution {
|
2024-05-17 18:23:38 +02:00
|
|
|
fun inorderTraversal(
|
|
|
|
root: TreeNode?,
|
|
|
|
values: MutableList<Int>,
|
|
|
|
): List<Int> {
|
2022-01-18 16:17:04 +01:00
|
|
|
if (root == null) {
|
|
|
|
return values
|
|
|
|
}
|
|
|
|
|
|
|
|
inorderTraversal(root.left, values)
|
|
|
|
values.add(root.`val`!!)
|
|
|
|
inorderTraversal(root.right, values)
|
|
|
|
|
|
|
|
return values
|
|
|
|
}
|
|
|
|
|
2024-05-17 18:23:38 +02:00
|
|
|
fun inorderTraversal(root: TreeNode?): List<Int> = inorderTraversal(root, mutableListOf<Int>())
|
2022-01-18 16:17:04 +01:00
|
|
|
}
|