@@ -60,7 +60,7 @@ def find_negative_index(array: list[int]):
60
60
def count_negatives_binary_search (grid : list [list [int ]]) -> int :
61
61
"""
62
62
An O(m logn) solution that uses binary search
63
- in order to find the boundary betweem positive and
63
+ in order to find the boundary between positive and
64
64
negative numbers
65
65
66
66
>>> count_negatives_binary_search(
@@ -107,7 +107,7 @@ def count_negatives_brute_force(grid: list[list[int]]) -> int:
107
107
108
108
def count_negatives_brute_force_with_break (grid : list [list [int ]]) -> int :
109
109
"""
110
- Similiar to the solution above, however uses break
110
+ Similar to the solution above, however uses break
111
111
in order to reduce the number of iterations
112
112
113
113
>>> count_negatives_brute_force_with_break(
@@ -133,7 +133,7 @@ def count_negatives_brute_force_with_break(grid: list[list[int]]) -> int:
133
133
def generate_large_matrix () -> list [list [int ]]:
134
134
"""
135
135
>>> generate_large_matrix() # doctest: +ELLIPSIS
136
- [[500 , ..., -499 ], [499 , ..., -501 ], ..., [2, ..., -998 ]]
136
+ [[1000 , ..., -999 ], [999 , ..., -1001 ], ..., [2, ..., -1998 ]]
137
137
"""
138
138
return [list (range (1000 - i , - 1000 - i , - 1 )) for i in range (1000 )]
139
139
@@ -144,17 +144,19 @@ def benchmark() -> None:
144
144
145
145
print ("Running benchmarks" )
146
146
setup = (
147
- "from __main__ import count_negatives_binary_search, count_negatives_brute_force, "
148
- "count_negatives_brute_force_with_break, generate_large_matrix"
147
+ "from __main__ import count_negatives_binary_search,count_negatives_brute_force"
148
+ ", count_negatives_brute_force_with_break,generate_large_matrix"
149
149
)
150
150
151
- cnbs = timeit (
151
+ print (
152
+ "count_negatives_binary_search()" ,
153
+ timeit (
152
154
"count_negatives_binary_search(generate_large_matrix())" ,
153
155
setup = setup ,
154
156
number = 5000 ,
155
157
),
156
-
157
- print ( "count_negatives_binary_search()" , cnbs [ 0 ], "seconds" )
158
+ "seconds" ,
159
+ )
158
160
print (
159
161
"count_negatives_brute_force_with_break()" ,
160
162
timeit (
@@ -163,7 +165,7 @@ def benchmark() -> None:
163
165
number = 5000 ,
164
166
),
165
167
"seconds" ,
166
- ) #
168
+ )
167
169
print (
168
170
"count_negatives_brute_force()" ,
169
171
timeit (
0 commit comments