Skip to content

Commit 9aa9505

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent e810066 commit 9aa9505

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

matrix/count_paths.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
0 1 * * 0 1 * *
2020
"""
2121

22+
intervals = [(4, 5), (0, 2), (2, 7), (1, 3), (0, 4)]
23+
intervals.sort(key=lambda x: x[1])
24+
count = 0
25+
end = 0
26+
answer = []
2227

23-
intervals = [(4, 5), (0, 2), (2, 7), (1, 3), (0, 4)]
24-
intervals.sort(key=lambda x: x[1])
25-
count = 0
26-
end = 0
27-
answer = []
28-
29-
for interval in intervals:
30-
if(end <= interval[0]):
31-
end = interval[1]
28+
for interval in intervals:
29+
if end <= interval[0]:
30+
end = interval[1]
3231
count += 1
33-
answer.append(interval)
32+
answer.append(interval)
3433

3534
if __name__ == "__main__":
3635
import doctest

scheduling/Iinterval_scheduling_algorithm.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@
55
66
"""
77

8+
89
def interval_scheduling(stimes, ftimes):
910
index = list(range(len(stimes)))
1011
# sort according to finish times
1112
index.sort(key=lambda item: ftimes[item])
12-
13+
1314
maximal_set = set()
1415
prev_finish_time = 0
1516
for item in index:
1617
if stimes[item] >= prev_finish_time:
1718
maximal_set.add(item)
1819
prev_finish_time = ftimes[item]
19-
20+
2021
return maximal_set
21-
22-
23-
n = int(input('Enter number of activities: '))
24-
stimes = input('Enter the start time of the {} activities in order: .{n}').split()
22+
23+
24+
n = int(input("Enter number of activities: "))
25+
stimes = input("Enter the start time of the {} activities in order: .{n}").split()
2526
stimes = [int(st) for st in stimes]
26-
ftimes = input('Enter the finish times of the {} activities in order:.{n}').split()
27+
ftimes = input("Enter the finish times of the {} activities in order:.{n}").split()
2728
ftimes = [int(ft) for ft in ftimes]
28-
29+
2930
ans = interval_scheduling(stimes, ftimes)
3031

3132

3233
if __name__ == "__main__":
3334
import doctest
3435

3536
doctest.testmod()
36-

0 commit comments

Comments
 (0)