We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 75349e0 commit a2b6e77Copy full SHA for a2b6e77
solution/1124.Longest Well-Performing Interval/Solution.java
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ public int longestWPI(int[] hours) {
3
+ int res = 0;
4
+ Map<Integer, Integer> map = new HashMap<>();
5
+ int s = 0;
6
+ for (int i = 0; i < hours.length; ++i) {
7
+ s += hours[i] > 8 ? 1 : -1;
8
+ if (s > 0) {
9
+ res = i + 1;
10
+ } else {
11
+ int b = map.getOrDefault(s - 1, -1);
12
+ if (b != -1) {
13
+ res = Math.max(res, i - b);
14
+ }
15
16
+ map.putIfAbsent(s, i);
17
18
+ return res;
19
20
+}
0 commit comments