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

Commit d407887

Browse files
committed
LeetCode 199
1 parent 4595cb4 commit d407887

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

‎solution/0100-0199/0199.Binary Tree Right Side View/README.md‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,30 @@
3838
<!-- 这里可写当前语言的特殊实现逻辑 -->
3939

4040
```java
41-
41+
class Solution {
42+
public List<Integer> rightSideView(TreeNode root) {
43+
List<Integer> ans = new ArrayList<>();
44+
robot(root, ans, 0);
45+
return ans;
46+
}
47+
48+
private void robot(TreeNode root, List<Integer> ans, int level) {
49+
if (root == null) {
50+
return;
51+
}
52+
if (ans.size() <= level) {
53+
ans.add(root.val);
54+
}
55+
ans.set(level, root.val);
56+
robot(root.left, ans, level + 1);
57+
robot(root.right, ans, level + 1);
58+
}
59+
}
4260
```
4361

4462
### **...**
4563
```
4664
4765
```
4866

49-
<!-- tabs:end -->
67+
<!-- tabs:end -->

‎solution/0100-0199/0199.Binary Tree Right Side View/README_EN.md‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,30 @@
4848
### **Java**
4949

5050
```java
51-
51+
class Solution {
52+
public List<Integer> rightSideView(TreeNode root) {
53+
List<Integer> ans = new ArrayList<>();
54+
robot(root, ans, 0);
55+
return ans;
56+
}
57+
58+
private void robot(TreeNode root, List<Integer> ans, int level) {
59+
if (root == null) {
60+
return;
61+
}
62+
if (ans.size() <= level) {
63+
ans.add(root.val);
64+
}
65+
ans.set(level, root.val);
66+
robot(root.left, ans, level + 1);
67+
robot(root.right, ans, level + 1);
68+
}
69+
}
5270
```
5371

5472
### **...**
5573
```
5674
5775
```
5876

59-
<!-- tabs:end -->
77+
<!-- tabs:end -->
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public List<Integer> rightSideView(TreeNode root) {
3+
List<Integer> ans = new ArrayList<>();
4+
robot(root, ans, 0);
5+
return ans;
6+
}
7+
8+
private void robot(TreeNode root, List<Integer> ans, int level) {
9+
if (root == null) {
10+
return;
11+
}
12+
if (ans.size() <= level) {
13+
ans.add(root.val);
14+
}
15+
ans.set(level, root.val);
16+
robot(root.left, ans, level + 1);
17+
robot(root.right, ans, level + 1);
18+
}
19+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /