In excercise "Count Negative Numbers in a Sorted Matrix" i use binary search, that is my code:
class Solution:
def countNegatives(self, grid: List[List[int]]) -> int:
def binary(nums):
l,r = 0,len(nums) - 1
while l<r:
pivot = l + (r-l) // 2
if nums[pivot] < 0:
r = pivot
else:
l = pivot + 1
return l
x = 0
for i in grid:
if i[-1] < 0:
x += len(i) - binary(i)
return xWhen i set "Python" i got time 100 ms, but when I chose "Python3" i got 132ms.
Could someone explain to me why there is such a difference ?
Thank you for your help :) (and sorry for my bad english)