Created
December 23, 2020 02:48
-
-
Save vamsitallapudi/a64a28b90d1e2c05c3ecef5e92bef4af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayDeque | |
import java.util.LinkedList | |
fun postOrderIterative(root: TreeNode?): List<Int> { | |
if(root == null) return emptyList() | |
val stack = ArrayDeque<TreeNode>() | |
val list = LinkedList<Int>() | |
stack.push(root) | |
while (stack.isNotEmpty()) { | |
val node = stack.pop() | |
list.addFirst(node.data) | |
node.left?.let { stack.push(it) } | |
node.right?.let { stack.push(it) } | |
} | |
return list | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment