Skip to content

Commit ee0e7b6

Browse files
committed
Runtime: 12 ms (Top 6.78%) | Memory: 59.90 MB (Top 5.93%)
1 parent 9023d33 commit ee0e7b6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Runtime: 12 ms (Top 6.78%) | Memory: 59.90 MB (Top 5.93%)
2+
3+
class Solution {
4+
public List<Integer> goodDaysToRobBank(int[] security, int time) {
5+
List<Integer> res = new ArrayList<>();
6+
if (time == 0) {
7+
for (int i = 0; i < security.length; i++) res.add(i);
8+
return res;
9+
}
10+
Set<Integer> set = new HashSet<>();
11+
int count = 1;
12+
for (int i = 1; i < security.length; i++) {
13+
if (security[i] <= security[i - 1]) {
14+
count++;
15+
} else {
16+
count = 1;
17+
}
18+
if (count > time) {
19+
set.add(i);
20+
}
21+
}
22+
23+
count = 1;
24+
for (int i = security.length - 2; i >= 0; i--) {
25+
if (security[i] <= security[i + 1]) {
26+
count++;
27+
} else {
28+
count = 1;
29+
}
30+
if (count > time && set.contains(i)) res.add(i);
31+
}
32+
return res;
33+
}
34+
}

0 commit comments

Comments
 (0)