1

来源:互联网 发布:python 爬虫工作原理 编辑:程序博客网 时间:2024/06/05 05:26
public class Solution {   public ArrayList<Integer> inorderTraversal(TreeNode root) {ArrayList<Integer> result = new ArrayList<Integer>();Stack<TreeNode> st = new Stack<TreeNode>();while (root != null || !st.isEmpty()) {if (root == null) {// Already in most left, visit left's parent, point to parent's right (subtree)root = st.pop();result.add(root.val);//System.out.print(root.val);//st.push(root.right);root = root.right;} else {// Not in most left, push parent, go to most left (subtree)st.push(root);root = root.left;}}return result;}}

0 0
原创粉丝点击