File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution :
2+ def maxProduct (self , nums : List [int ]) -> int :
3+ answer = max (nums )
4+
5+ cumprod = 1
6+ cumprod_to_first_neg = 1
7+
8+ for num in nums :
9+ if num == 0 :
10+ cumprod = 1
11+ cumprod_to_first_neg = 1
12+ else :
13+ cumprod *= num
14+ if cumprod > 0 :
15+ answer = max (answer , cumprod )
16+ else :
17+ answer = max (answer , cumprod // cumprod_to_first_neg )
18+ if cumprod_to_first_neg > 0 :
19+ cumprod_to_first_neg *= num
20+ return answer
21+
Original file line number Diff line number Diff line change 1+ from collections import Counter , defaultdict
2+ class Solution :
3+ def minWindow (self , s : str , t : str ) -> str :
4+ answer = ''
5+ counter = Counter (t )
6+ now = defaultdict ()
7+
8+ start = 0
9+ end = 0
10+
11+ now [s [start ]] = 1
12+
13+ while start <= end and end < len (s ):
14+ enough = True
15+ for key in counter .keys ():
16+ if key not in now or now [key ] < counter [key ]:
17+ enough = False
18+
19+ if enough :
20+ if answer == '' or len (answer ) > end - start + 1 :
21+ answer = s [start :end + 1 ]
22+
23+ now [s [start ]] -= 1
24+ start += 1
25+ else :
26+ end += 1
27+ if end == len (s ):
28+ break
29+ if s [end ] not in now :
30+ now [s [end ]] = 0
31+ now [s [end ]] += 1
32+
33+ return answer
34+
You can’t perform that action at this time.
0 commit comments