File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Largest Contiguous Subarray Problem Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ int findMaxLength (int nums[], int n)
2
+ {
3
+ int maxlen = 0 ;
4
+
5
+ for (int start = 0 ; start < n; start++)
6
+ {
7
+ int zeroes = 0 , ones = 0 ;
8
+
9
+ for (int end = start; end < n; end++)
10
+ {
11
+ if (nums[end] == 0 )
12
+ {
13
+ zeroes++;
14
+ }
15
+ else
16
+ {
17
+ ones++;
18
+ }
19
+ if (zeroes == ones)
20
+ {
21
+ maxlen = max (maxlen, end - start + 1 );
22
+ }
23
+ }
24
+ }
25
+ return maxlen;
26
+ }
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+
3
+ def findMaxLength (nums ):
4
+ maxlen = 0
5
+ for start in range (0 , len (nums )):
6
+ zeroes = 0
7
+ ones = 0
8
+ for end in range (start , len (nums )):
9
+ if nums [end ] == 0 :
10
+ zeroes += 1
11
+ else :
12
+ ones += 1
13
+
14
+ if zeroes == ones :
15
+ maxlen = max (maxlen , end - start + 1 )
16
+
17
+ return maxlen
You can’t perform that action at this time.
0 commit comments