mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
对Java版本前序排列的修改
This commit is contained in:
@ -116,19 +116,19 @@ Java:
|
||||
```Java
|
||||
// 前序遍历·递归·LC144_二叉树的前序遍历
|
||||
class Solution {
|
||||
ArrayList<Integer> preOrderReverse(TreeNode root) {
|
||||
ArrayList<Integer> result = new ArrayList<Integer>();
|
||||
preOrder(root, result);
|
||||
public List<Integer> preorderTraversal(TreeNode root) {
|
||||
List<Integer> result = new ArrayList<Integer>();
|
||||
preorder(root, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void preOrder(TreeNode root, ArrayList<Integer> result) {
|
||||
public void preorder(TreeNode root, List<Integer> result) {
|
||||
if (root == null) {
|
||||
return;
|
||||
}
|
||||
result.add(root.val); // 注意这一句
|
||||
preOrder(root.left, result);
|
||||
preOrder(root.right, result);
|
||||
result.add(root.val);
|
||||
preorder(root.left, result);
|
||||
preorder(root.right, result);
|
||||
}
|
||||
}
|
||||
// 中序遍历·递归·LC94_二叉树的中序遍历
|
||||
|
Reference in New Issue
Block a user