Created
August 22, 2017 21:59
-
-
Save cixuuz/3927083fc3ec44bcb0c70c07ada06b09 to your computer and use it in GitHub Desktop.
[94. Binary Tree Inorder Traversal] #leetcode
This file contains hidden or 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
| class Solution { | |
| public List<Integer> inorderTraversal(TreeNode root) { | |
| List<Integer> result = new ArrayList<Integer>(); | |
| Stack<TreeNode> stack = new Stack<TreeNode>(); | |
| while ( !stack.isEmpty() || root != null ) { | |
| if ( root != null ) { | |
| stack.push(root); | |
| root = root.left; | |
| } else { | |
| TreeNode node = stack.pop(); | |
| result.add(node.val); | |
| root = node.right; | |
| } | |
| } | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment