当前位置: 首页 > news >正文

LeetCode1124. Longest Well-Performing Interval

文章目录

    • 一、题目
    • 二、题解

一、题目

We are given hours, a list of the number of hours worked per day for a given employee.

A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.

A well-performing interval is an interval of days for which the number of tiring days is strictly larger than the number of non-tiring days.

Return the length of the longest well-performing interval.

Example 1:

Input: hours = [9,9,6,0,6,6,9]
Output: 3
Explanation: The longest well-performing interval is [9,9,6].
Example 2:

Input: hours = [6,6,6]
Output: 0

Constraints:

1 <= hours.length <= 104
0 <= hours[i] <= 16

二、题解

class Solution {
public:int longestWPI(vector<int>& hours) {int n = hours.size();unordered_map<int,int> map;int res = 0,sum = 0;map[0] = -1;for(int i = 0;i < n;i++){hours[i] > 8 ? sum += 1 : sum += -1;if(sum > 0) res = i + 1;else{if(map.find(sum-1) != map.end()){res = max(res,i-map[sum-1]);}}if(map.find(sum) == map.end()) map[sum] = i;}return res;}
};
http://www.lryc.cn/news/280297.html

相关文章:

  • 如何使用手机公网远程访问本地群辉Video Station中视频文件【内网穿透】
  • 事件分析应急响应-Server2229(环境+解析)
  • SpringCloud:微服务
  • 拥抱Guava之集合操作
  • 运算放大器相关知识总结(1)
  • ZMQ_REQ\REP模式
  • 机器人跟踪性能量化指标
  • 【GitHub项目推荐--开源的坦克大战】【转载】
  • 06、Kafka ------ 各个功能的作用解释(ISR 同步副本、非同步副本、自动创建主题、修改主题、删除主题)
  • Spring Security实现详解
  • ⭐Unity LeapMotion与手的相关开发
  • React16源码: React中的update和updateQueue的源码实现
  • mybatisplus(service CRUD 接口)
  • GC6109——双通道5V低电压步进电机驱动芯片,低噪声、低振动,应用摄像机,机器人等产品中
  • MySQL-多表联合查询
  • 商城小程序(8.购物车页面)
  • [Vulnhub靶机] DC-1
  • 【springboot 中集成 knife4j 时,报错 No mapping for GET /doc.html】
  • C++ 具名要求-全库范围的概念 -谓词(Predicate)-二元谓词(BinaryPredicate)
  • MyBatis-Plus不写任何resultMap和SQL执行一对一、一对多、多对多关联查询
  • arcgis javascript api4.x加载天地图web墨卡托(wkid:3857)坐标系
  • 中职组安全-win20230217-环境-解析
  • PMP学习考试经验总结
  • leetcode206.反转链表
  • python每日学17:控制推导逻辑的子表达式不要超过两个
  • 地质时间与数值模拟时间转换(mm/Ma-->m/s)
  • linux文件描述符管理
  • 谷歌翻译不能使用 host添加IP
  • Redis命令 - Lists命令组常用命令
  • 切分大文件sql为小份