let hours = [9,9,6,0,6,6,9]
hours.forEach((val,index)=>{
if(val > 8){
hours[index] = 1
}else{
hours[index] = -1
}
})
let prefix = Array(hours.length+1)
prefix[0]=0
for(let i = 1;i<prefix.length;i++){
prefix[i] = prefix[i-1]+hours[i-1]
}
let max = 0
for(let i = 0;i<prefix.length;i++){
for(let j = i+1;j<prefix.length;j++){
if(j-i>max&&prefix[j]-prefix[i]>0){
max = j-i
}
}
}
console.log(max);
1124表现良好的最长时间段
最新推荐文章于 2024-09-11 22:31:16 发布