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