5 ms·
Nice read! I've been toying around with a few hypothetical improvements on my machine. For this case: nums = [100, 6, 5, 100, 4, 4] desired_result = 743 My
by estomagordo 7y ago
Nice read!
I've been toying around with a few hypothetical improvements on my machine.
For this case:
nums = [100, 6, 5, 100, 4, 4]
desired_result = 743
My machine finished the original implementation in:
07:53
I then tried skipping the set of operators and just doing list lookups (figuring the set overhead defeats the advantage when the collection is so small):
08:24
My next idea was to replace the set lookup with an isinstance() check:
09:01
My third proposed change is the only one that has given me a speed-up:
Moving the list() call of r to inside the try:
06:47