网站推广去哪家比较好,dw网页制作教程个人网站,北京网站建设推广服务信息,wordpress 获取题目 给你一份工作时间表 hours#xff0c;上面记录着某一位员工每天的工作小时数。 我们认为当员工一天中的工作小时数大于 8 小时的时候#xff0c;那么这一天就是「劳累的一天」。 所谓「表现良好的时间段」#xff0c;意味在这段时间内#xff0c;「劳累的天数」是严格…题目 给你一份工作时间表 hours上面记录着某一位员工每天的工作小时数。 我们认为当员工一天中的工作小时数大于 8 小时的时候那么这一天就是「劳累的一天」。 所谓「表现良好的时间段」意味在这段时间内「劳累的天数」是严格 大于「不劳累的天数」。 请你返回「表现良好时间段」的最大长度。 示例 1 输入hours [9,9,6,0,6,6,9] 输出3 解释最长的表现良好时间段是 [9,9,6]。 提示 1 hours.length 10000 0 hours[i] 16 来源力扣LeetCode 链接https://leetcode-cn.com/problems/longest-well-performing-interval 著作权归领扣网络所有。商业转载请联系官方授权非商业转载请注明出处。 解答
class Solution {public int longestWPI(int[] hours) {if (hours null || hours.length 0) {return 0;}int maxCount 0;int length hours.length;int iLength length;int jLength length;for (int i 0; i iLength; i) {int hard 0;int easy 0;int count 0;for (int j i; j jLength; j) {if (hours[j] 8) {hard;}else {easy;}count;if (hard easy) {if (count maxCount) {maxCount count;}}}}return maxCount;}
}要点 当前给出的实现仅能满足功能无法满足题目对性能的要求。但受限于当前的工作状态没有太多时间投入因此暂时先做到这个程度。
准备的用例如下 Testpublic void test01() {int[] hours new int[] { 9, 9, 6, 0, 6, 6, 9 };assertEquals(3, new L1124().longestWPI(hours));}Testpublic void test0101() {int[] hours new int[] { 8, 8, 6, 0, 6, 6, 9 };assertEquals(1, new L1124().longestWPI(hours));}Testpublic void test0102() {int[] hours new int[] { 6 };assertEquals(0, new L1124().longestWPI(hours));}Testpublic void test0103() {int[] hours new int[] { 9 };assertEquals(1, new L1124().longestWPI(hours));}Testpublic void test02() {int[] hours new int[] { 9, 6, 9, 6, 9, 6, 6 };assertEquals(5, new L1124().longestWPI(hours));}Testpublic void test03() {int[] hours new int[] { 9, 6, 9, 6, 9, 6, 6, 9, 9, 9 };assertEquals(10, new L1124().longestWPI(hours));}Testpublic void test04() {int[] hours new int[] { 8, 9, 6, 9, 6, 9, 6, 6, 9, 9, 9, 6 };assertEquals(10, new L1124().longestWPI(hours));}