题目
https://leetcode-cn.com/problems/binary-tree-inorder-traversal/
题解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> result = new ArrayList<Integer>(); helper(root, result); return result; } private void helper(TreeNode root, List<Integer> ret) { if (root != null) { helper(root.left, ret); ret.add(root.val); helper(root.right, ret); } } }
|