3 ms·
Why do you need the minimum == 0 test in the following chunk of code ... if i > 0 and (minimum == 0 or i < minimum): minimum = i
by rational_indian 6y ago
Why do you need the minimum == 0 test in the following chunk of code ...
if i > 0 and (minimum == 0 or i < minimum):
minimum = i
- mlthoughts2018 6y agoThe stated problem requires returning the smallest integer greater than 0 in the list. 0 will only be the running minimum if only non-positive numbers have been seen so far, and since i is greater than zero in the condition, if minimum == 0 it means i is the first positive integer we’ve seen, so even though i > minimum (i > 0) we need to swap i as the minimum at that point.
- rational_indian 6y agoThanks, that explains it.