Class Solution

java.lang.Object
g0501_0600.s0525_contiguous_array.Solution

public class Solution extends Object
525 - Contiguous Array.<p>Medium</p> <p>Given a binary array <code>nums</code>, return <em>the maximum length of a contiguous subarray with an equal number of</em> <code>0</code> <em>and</em> <code>1</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [0,1]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> [0, 1] is the longest contiguous subarray with an equal number of 0 and 1.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [0,1,0]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.</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> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findMaxLength

      public int findMaxLength(int[] nums)