Array Question 11
Question 26. Write a Program to return the maximum length of contiguous subarray with an equal no of 0 and 1.
Program
class Solution { public int findMaxLength(int[] nums) { int count = 0; for (int i = 0; i < nums.length; i++) { int zeros = 0, ones = 0; for (int j = i; j < nums.length; j++) { if (nums[j] == 0) { zeros++; } else { ones++; } if (zeros == ones) { count = Math.max(count, j - i + 1); } } } return count; } } |