145. Binary Tree Postorder Traversal
/**
* 145. Binary Tree Postorder Traversal
* https://leetcode.com/problems/binary-tree-postorder-traversal/description/
* @param {TreeNode} root
* @return {number[]}
* Postorder: 左->右->根
*/
//kotlin
fun postorderTraversal(root_: TreeNode?): List<Int>? { val result = arrayListOf<Int>()//read,write var root = root_ val stack = Stack<TreeNode>() while (root != null || stack.size > 0) { if (root != null) { stack.push(root) result.add(0,root.`val`) root = root.right//loop right node } else { root = stack.pop() root = root.left } } return result }