forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_1441.java
31 lines (29 loc) · 863 Bytes
/
_1441.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class _1441 {
public static class Solution1 {
public List<String> buildArray(int[] target, int n) {
List<String> result = new ArrayList<>();
Set<Integer> set = new HashSet<>();
for (int i : target) {
set.add(i);
}
int max = target[target.length - 1];
for (int i = 1; i <= n; i++) {
if (!set.contains(i)) {
result.add("Push");
result.add("Pop");
} else {
result.add("Push");
}
if (i == max) {
break;
}
}
return result;
}
}
}