Skip to content

Commit a5be9d0

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

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

Dog Pattern

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def dog_pattern():
2-
2+
33
print(" / \__")
44
print(" ( @\__")
55
print("/ o")

Merge sort

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ def merge_sort_files(file_input, file_output):
44
# Read input file
55
with open(file_input, 'r') as f:
66
arr = list(map(int, f.read().split()))
7-
7+
88
# Sort the array
99
arr = merge_sort(arr)
10-
10+
1111
# Write sorted data to the output file
1212
with open(file_output, 'w') as f:
1313
f.write(" ".join(map(str, arr)))
1414

1515
def merge_sort(arr):
1616
if len(arr) <= 1:
1717
return arr
18-
18+
1919
mid = len(arr) // 2
2020
left_half = merge_sort(arr[:mid])
2121
right_half = merge_sort(arr[mid:])
22-
22+
2323
return merge(left_half, right_half)
2424

2525
def merge(left, right):

Stack.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
def largest_rectangle_area(heights):
2-
stack = []
3-
max_area = 0
4-
index = 0
5-
6-
while index < len(heights):
7-
if not stack or heights[stack[-1]] <= heights[index]:
8-
stack.append(index)
9-
index += 1
10-
11-
else:
12-
top_of_stack = stack.pop()
13-
area = (heights[top_of_stack]* ((index - stack[-1] -1) if stack else index))
14-
15-
max_area = max(max_area,area)
16-
17-
while stack:
18-
top_of_stack = stack.pop()
19-
area = (heights[top_of_stack] * ((index - stack[-1] -1) if stack else index))
20-
max_area = max(max_area, area)
21-
22-
return max_area
2+
stack = []
3+
max_area = 0
4+
index = 0
5+
6+
while index < len(heights):
7+
if not stack or heights[stack[-1]] <= heights[index]:
8+
stack.append(index)
9+
index += 1
10+
11+
else:
12+
top_of_stack = stack.pop()
13+
area = heights[top_of_stack] * ((index - stack[-1] - 1) if stack else index)
14+
15+
max_area = max(max_area, area)
16+
17+
while stack:
18+
top_of_stack = stack.pop()
19+
area = heights[top_of_stack] * ((index - stack[-1] - 1) if stack else index)
20+
max_area = max(max_area, area)
21+
22+
return max_area
23+
2324

2425
histogram = [2, 1, 5, 6, 2, 3]
2526

0 commit comments

Comments
 (0)