首页 > 代码库 > leetcode94

leetcode94

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left;
 *     public TreeNode right;
 *     public TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    Stack<int> S = new Stack<int>();
        private void inOrder(TreeNode node)
        {
            if (node != null)
            {
                if (node.left != null)
                {
                    inOrder(node.left);
                }
                S.Push(node.val);
                if (node.right != null)
                {
                    inOrder(node.right);
                }
            }
        }

        public IList<int> InorderTraversal(TreeNode root)
        {
            inOrder(root);
            var list = S.Reverse().ToList();
            return list;
        }
}

https://leetcode.com/problems/binary-tree-inorder-traversal/#/description

leetcode94