-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFindGoodDaysToRobTheBank.java
31 lines (30 loc) · 1.07 KB
/
FindGoodDaysToRobTheBank.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
/*https://leetcode.com/problems/find-good-days-to-rob-the-bank/*/
class Solution {
public List<Integer> goodDaysToRobBank(int[] security, int time) {
List<Integer> result = new ArrayList<Integer>();
if (time == 0)
{
for (int i = 0; i < security.length; ++i)
result.add(i);
return result;
}
int n = security.length;
int[] left = new int[n], right = new int[n];
for (int i = 1; i < n; ++i)
if (security[i] <= security[i-1])
left[i] = left[i-1]+1;
for (int i = n-2; i >= 0; --i)
if (security[i] <= security[i+1])
right[i] = right[i+1]+1;
// for (int i = 0; i < n; ++i)
// System.out.print(left[i]+" ");
// System.out.println();
// for (int i = 0; i < n; ++i)
// System.out.print(right[i]+" ");
// System.out.println();
for (int i = time; i < n-time; ++i)
if (left[i] >= time && right[i] >= time)
result.add(i);
return result;
}
}