Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e6f7cc9

Browse files
refactor 199
1 parent e3603ed commit e6f7cc9

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ Your ideas/fixes/algorithms are more than welcome!
419419
|202|[Happy Number](https://leetcode.com/problems/happy-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_202.java)| O(k)|O(k) | Easy
420420
|201|[Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_201.java)| O(min(m,n))|O(1) | Medium | Bit Manipulation
421421
|200|[Number of Islands](https://leetcode.com/problems/number-of-islands/)|[Solution](../master/MEDIUM/src/medium/_200.java)| O(m*n)|O(m*n) | Medium| Union Find, DFS
422-
|199|[Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_199.java)| O(n)|O(n)| Medium | BFS
422+
|199|[Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_199.java)| O(n)|O(h)| Medium | BFS
423423
|198|[House Robber](https://leetcode.com/problems/house-robber/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_198.java)| O(n)|O(n)| Easy | DP
424424
|191|[Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_191.java)| O(n)|O(1)| Easy | Bit Manipulation
425425
|190|[Reverse Bits](https://leetcode.com/problems/reverse-bits/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_190.java)| O(n)|O(1)| Easy | Bit Manipulation

src/main/java/com/fishercoder/solutions/_199.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public List<Integer> rightSideView(TreeNode root) {
3333
int size = q.size();
3434
for (int i = 0; i < size; i++) {
3535
TreeNode curr = q.poll();
36-
if (i == size-1) {
36+
if (i == size - 1) {
3737
result.add(curr.val);
3838
}
3939
if (curr.left != null) {
@@ -46,17 +46,5 @@ public List<Integer> rightSideView(TreeNode root) {
4646
}
4747
return result;
4848
}
49-
50-
public static void main(String...strings){
51-
_199 test = new _199();
52-
TreeNode root = new TreeNode(1);
53-
root.left = new TreeNode(2);
54-
root.right = new TreeNode(3);
55-
root.left.right = new TreeNode(5);
56-
root.right.right = new TreeNode(4);
57-
List<Integer> result = test.rightSideView(root);
58-
for(int i : result){
59-
System.out.print(i + ", ");
60-
}
61-
}
62-
}
49+
50+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.classes.TreeNode;
4+
import com.fishercoder.common.utils.TreeUtils;
5+
import com.fishercoder.solutions._199;
6+
import org.junit.BeforeClass;
7+
import org.junit.Test;
8+
9+
import java.util.Arrays;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
public class _199Test {
14+
private static _199 test;
15+
private static TreeNode root;
16+
17+
@BeforeClass
18+
public static void setup() {
19+
test = new _199();
20+
}
21+
22+
@Test
23+
public void test1() {
24+
root = TreeUtils.constructBinaryTree(Arrays.asList(1, null, 3));
25+
assertEquals(Arrays.asList(1, 3), test.rightSideView(root));
26+
}
27+
28+
}

0 commit comments

Comments
 (0)