-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (40 loc) · 1.27 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import time
from typing import List
from helpers.show_menu import show_menu
from sorting_algorithms import insertion_sort, selection_sort, bubble_sort, quick_sort
import types
import numpy as np
# def main():
# show_menu()
def productExceptSelf(nums: List[int]) -> List[int]:
n = len(nums)
product = [1] * n
prefix = 1
for i in range(n):
product[i] *= prefix
prefix *= nums[i]
sufix = 1
for i in range(n-1, -1, -1):
product[i] *= sufix
sufix *= nums[i]
return product
def findMaxLength(nums: List[int]) -> int:
count = 0
maximo_atual = 0
dic = {0: -1}
atual = []
for i, value in enumerate(nums):
if nums[i] == 0:
count -= 1
else:
count += 1
if count in dic:
maximo_atual = max(maximo_atual, i - dic[count])
else:
dic[count] = i
atual.append(value)
if count == 0 and len(atual) % 2 == 0:
maximo_atual = len(atual)
return maximo_atual
if __name__ == "__main__":
print(findMaxLength([1,1,1,1,1,1,1,0,0,0,0,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,1,1,0,0,0,0,1,0,0,1,1,1,1,1,0,0,1,0,1,1,0,0,0,1,0,0,0,1,1,1,0,1,1,0,1,0,0,1,1,0,1,0,0,1,1,1,0,0,1,0,1,1,1,0,0,1,0,1,1]))