Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8dc8ba6

Browse files
committed
0144 problem added
1 parent08c263e commit8dc8ba6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode() {}
8+
* TreeNode(int val) { this.val = val; }
9+
* TreeNode(int val, TreeNode left, TreeNode right) {
10+
* this.val = val;
11+
* this.left = left;
12+
* this.right = right;
13+
* }
14+
* }
15+
*/
16+
classSolution {
17+
18+
staticvoidpreOrder(TreeNoderoot,List<Integer>res){
19+
20+
21+
if(root ==null){
22+
return;
23+
}
24+
res.add(root.val);
25+
preOrder(root.left,res);
26+
preOrder(root.right,res);
27+
28+
}
29+
30+
publicList<Integer>preorderTraversal(TreeNoderoot) {
31+
32+
List<Integer>res =newArrayList<>();
33+
34+
preOrder(root,res);
35+
36+
returnres;
37+
38+
}
39+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp