本文主要是介绍Leetcode 525. Contiguous Array,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
class Solution {
public:int findMaxLength(vector<int>& nums) {int length = 0;int sum = 0;unordered_map<int, int> m({{0, -1}});for(int i = 0; i < nums.size(); i++) {sum += nums[i]?1:-1;if(m.count(sum)) {length = max(length, i - m[sum]);}else {m[sum] = i;}}return length;}
};
Reference
- https://leetcode.com/problems/contiguous-array/description/
这篇关于Leetcode 525. Contiguous Array的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!