标签:des style blog color io ar div sp log
public class Solution { public List<Integer> preorderTraversal(TreeNode root) { List<Integer> result = new ArrayList<Integer>(); Stack<TreeNode> nodeStack = new Stack<TreeNode>(); TreeNode nowNode = root; while (!nodeStack.isEmpty() || nowNode != null) { if (nowNode != null) { result.add(nowNode.val); nodeStack.push(nowNode.right); nodeStack.push(nowNode.left); } nowNode = nodeStack.pop(); } return result; } }
[LeetCode] Binary Tree Preorder Traversal
标签:des style blog color io ar div sp log
原文地址:http://www.cnblogs.com/yuhaos/p/3958742.html