File tree 1 file changed +34
-0
lines changed
scripts/algorithms/F/Find Good Days to Rob the Bank
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments