Skip to content

Commit 743e36c

Browse files
committed
Time: 625 ms (54.94%) | Memory: 22.3 MB (62.71%) - LeetSync
1 parent 917b3c7 commit 743e36c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def findMaxLength(self, nums: List[int]) -> int:
3+
_dict = {}
4+
_dict[0] = -1
5+
count = 0
6+
max_len = 0
7+
8+
for i in range(len(nums)):
9+
if nums[i] == 0:
10+
count -= 1
11+
elif nums[i] == 1:
12+
count += 1
13+
14+
if count in _dict:
15+
max_len = max(max_len, i - _dict[count])
16+
else:
17+
_dict[count] = i
18+
return max_len

0 commit comments

Comments
 (0)