Skip to content

Commit 4bd4971

Browse files
add 1441
1 parent 418b70a commit 4bd4971

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1441|[Build an Array With Stack Operations](https://leetcode.com/problems/build-an-array-with-stack-operations/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1441.java) | |Easy|Stack|
1112
|1437|[Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1437.java) | |Medium|Array|
1213
|1436|[Destination City](https://leetcode.com/problems/destination-city/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1436.java) | |Easy|String|
1314
|1432|[Max Difference You Can Get From Changing an Integer](https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1432.java) | |Medium|String|
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashSet;
5+
import java.util.List;
6+
import java.util.Set;
7+
8+
public class _1441 {
9+
public static class Solution1 {
10+
public List<String> buildArray(int[] target, int n) {
11+
List<String> result = new ArrayList<>();
12+
Set<Integer> set = new HashSet<>();
13+
for (int i : target) {
14+
set.add(i);
15+
}
16+
int max = target[target.length - 1];
17+
for (int i = 1; i <= n; i++) {
18+
if (!set.contains(i)) {
19+
result.add("Push");
20+
result.add("Pop");
21+
} else {
22+
result.add("Push");
23+
}
24+
if (i == max) {
25+
break;
26+
}
27+
}
28+
return result;
29+
}
30+
}
31+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1441;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import java.util.Arrays;
8+
9+
import static junit.framework.TestCase.assertEquals;
10+
11+
public class _1441Test {
12+
private static _1441.Solution1 solution1;
13+
private static int[] target;
14+
15+
@BeforeClass
16+
public static void setup() {
17+
solution1 = new _1441.Solution1();
18+
}
19+
20+
@Test
21+
public void test1() {
22+
target = new int[]{1, 3};
23+
assertEquals(Arrays.asList("Push", "Push", "Pop", "Push"), solution1.buildArray(target, 3));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)