我的答案:(1ms)
public List<Integer> inorderTraversal(TreeNode root) { List result = new ArrayList(); if (null != root) { result.addAll(inorderTraversal(root.left)); result.add(root.val); result.addAll(inorderTraversal(root.right)); } return result; }参考答案:(0ms)
public List<Integer> inorderTraversal(TreeNode root) { List<Integer> list=new ArrayList<>(); traversal(root, list); return list; } public void traversal(TreeNode root,List<Integer> list) { if(root!=null){ traversal(root.left, list); list.add(root.val); traversal(root.right, list); } } 98. 验证二叉搜索树