mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 09:59:41 +01:00
27 lines
637 B
Kotlin
27 lines
637 B
Kotlin
|
/**
|
||
|
* 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 {
|
||
|
fun inorderTraversal(root: TreeNode?, values: MutableList<Int>): List<Int> {
|
||
|
if (root == null) {
|
||
|
return values
|
||
|
}
|
||
|
|
||
|
inorderTraversal(root.left, values)
|
||
|
values.add(root.`val`!!)
|
||
|
inorderTraversal(root.right, values)
|
||
|
|
||
|
return values
|
||
|
}
|
||
|
|
||
|
fun inorderTraversal(root: TreeNode?): List<Int>
|
||
|
= inorderTraversal(root, mutableListOf<Int>())
|
||
|
}
|