-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
70 lines (47 loc) · 869 Bytes
/
test.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
55
56
57
58
59
60
61
62
63
64
65
66
67
import operator
def longest_mult(arr):
tm = None
m = 0
tm1 = 1
tm2 = 1
fn = False
for j in arr:
if j < 0:
tm = None
tm1 *= j
if not fn:
fn = True
elif fn:
tm2 *= j
elif j > 0:
tm1 *= j
if not tm:
tm = j
else:
tm *= j
if tm > m:
m = tm
if fn:
tm2 *= j
if tm1 > m:
m = tm1
if tm2 > m:
m = tm2
print m
return m
def mul(arr):
print reduce(operator.mul, arr)
arr = [1,2,3,-4,-9,-10,-110,5,6,7,8]
longest_mult(arr)
mul(arr)
arr = [-1,-2,-3,-4,-5]
longest_mult(arr)
mul([2,3,4,5])
arr = [-6,-2,-3,-4,-5]
longest_mult(arr)
mul([2,3,4,6])
arr = [-6,10,-2,10,-3,-4,-5]
longest_mult(arr)
mul([2,3,4,6, 10, 10])
arr = [0]
longest_mult(arr)