525. Contiguous Array Medium
1/**
2 * [525] Contiguous Array
3 *
4 * Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.
5 *
6 * Example 1:
7 *
8 * Input: nums = [0,1]
9 * Output: 2
10 * Explanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1.
11 *
12 * Example 2:
13 *
14 * Input: nums = [0,1,0]
15 * Output: 2
16 * Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.
17 *
18 *
19 * Constraints:
20 *
21 * 1 <= nums.length <= 10^5
22 * nums[i] is either 0 or 1.
23 *
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/contiguous-array/
28// discuss: https://leetcode.com/problems/contiguous-array/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33 pub fn find_max_length(nums: Vec<i32>) -> i32 {
34 0
35 }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn test_525() {
46 }
47}
48
Back
© 2025 bowen.ge All Rights Reserved.