upd
This commit is contained in:
29
algorithms/labs/lab6/code/3.py
Normal file
29
algorithms/labs/lab6/code/3.py
Normal file
@@ -0,0 +1,29 @@
|
||||
def longest_increasing_run(a):
|
||||
if not a:
|
||||
return 0, -1, -1
|
||||
best_len = 1
|
||||
best_l = 0
|
||||
best_r = 0
|
||||
cur_len = 1
|
||||
cur_l = 0
|
||||
for i in range(1, len(a)):
|
||||
if a[i] > a[i - 1]:
|
||||
cur_len += 1
|
||||
else:
|
||||
if cur_len > best_len:
|
||||
best_len = cur_len
|
||||
best_l = cur_l
|
||||
best_r = i - 1
|
||||
cur_len = 1
|
||||
cur_l = i
|
||||
if cur_len > best_len:
|
||||
best_len = cur_len
|
||||
best_l = cur_l
|
||||
best_r = len(a) - 1
|
||||
return best_len, best_l, best_r
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
a = [1, 2, 3, -1, 0, 1, 1, 2, 3, 4, -5]
|
||||
length, l, r = longest_increasing_run(a)
|
||||
print(length, l, r)
|
||||
Reference in New Issue
Block a user