java.lang.Object
g1001_1100.s1004_max_consecutive_ones_iii.Solution

public class Solution extends Object
1004 - Max Consecutive Ones III.<p>Medium</p> <p>Given a binary array <code>nums</code> and an integer <code>k</code>, return <em>the maximum number of consecutive</em> <code>1</code><em>&rsquo;s in the array if you can flip at most</em> <code>k</code> <code>0</code>&rsquo;s.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> [1,1,1,0,0, <strong>1</strong> ,1,1,1,1, <strong>1</strong> ] Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3</p> <p><strong>Output:</strong> 10</p> <p><strong>Explanation:</strong> [0,0,1,1, <strong>1</strong> , <strong>1</strong> ,1,1,1, <strong>1</strong> ,1,1,0,0,0,1,1,1,1] Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li> <li><code>0 <= k <= nums.length</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • longestOnes

      public int longestOnes(int[] a, int k)