-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask04.py
More file actions
32 lines (23 loc) · 849 Bytes
/
task04.py
File metadata and controls
32 lines (23 loc) · 849 Bytes
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
# coding=utf-8
# В последовательности a(n) найти количество отрицательных элементов, расположенных
# между двумя первыми нулевыми элементами.
def num_negatives_between_two_first_zeroes(arr):
index_left = -1
index_right = -1
for i in range(len(arr)):
if arr[i] == 0:
if index_left == -1:
index_left = i
continue
if index_right == -1:
index_right = i
if index_left == -1 or index_right == -1:
return -1
if index_left == index_right - 1:
return 0
part = arr[index_left + 1:index_right]
num_negatives = 0
for i in range(len(part)):
if part[i] < 0:
num_negatives += 1
return num_negatives