Skip to content

Commit b961766

Browse files
authored
Create 1124. Longest Well-Performing Interval
1 parent ca8d57b commit b961766

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {number[]} hours
3+
* @return {number}
4+
*/
5+
var longestWPI = function(hours) {
6+
let ans = 0;
7+
8+
for (let i = 0; i < hours.length; i++) {
9+
let sum = 0;
10+
11+
for (let j = i; j < hours.length; j++) {
12+
if (hours[j] > 8) {
13+
sum += 1;
14+
} else {
15+
sum -= 1;
16+
}
17+
18+
if (sum > 0) {
19+
ans = Math.max(ans, j - i + 1);
20+
}
21+
}
22+
}
23+
24+
return ans;
25+
};

0 commit comments

Comments
 (0)