public static int longestOnes(int[] nums,int k) { // write code here if (nums.length == 0) { return 0; } int left = 0; int right = 0; int maxLength = Integer.MIN_VALUE; int sumOne = 0; while (right < nums.length) { if (nums[right] == 0) { sumOne++; } while (sumOne > k) { if (nums[left] == 0) { sumOne--; } left++; } maxLength = Math.max(maxLength, right - left + 1); right++; } return maxLength; } 滑动窗口法
点赞

相关推荐

09-26 19:45
门头沟学院 Java
点赞 评论 收藏
分享
牛客21331815...:像我一投就pass,根本不用焦虑泡池子
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务