We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2e54d6c commit 1703022Copy full SHA for 1703022
Day26.cpp
@@ -0,0 +1,37 @@
1
+/*
2
+ Author: Aryan Yadav
3
+ Contiguous Array
4
+
5
+ Algorithm: Two pointer
6
+ Difficulty: Medium
7
+*/
8
+class Solution {
9
+public:
10
+ int findMaxLength(vector<int>& nums) {
11
+ unordered_map<int, int> m;
12
+ int sum = 0;
13
+ int max_len = 0;
14
+ int end_ind = -1;
15
+ int n = nums.size();
16
+ for(int i=0;i<n;i++){
17
+ if(nums[i] == 0)
18
+ nums[i] = -1;
19
+ }
20
21
+ sum+=nums[i];
22
+ if(sum == 0){
23
+ max_len = i+1;
24
+ end_ind = i;
25
26
+ if(m.find(sum+n) != m.end()){
27
+ if(max_len<i - m[sum+n]){
28
+ max_len = i - m[sum+n];
29
30
31
32
+ else
33
+ m[sum+n] = i;
34
35
+ return max_len;
36
37
+};
0 commit comments