▲ | sfn42 2 days ago | |
for i in range(n - 1): Is pretty much a standard for loop. Between that and for n in numbers: You can do pretty much the same things as a more conventional language. You could also solve it pretty simply like this: expected_sum = (n * (n + 1)) / 2 missing_num = expected_sum - sum(numbers) This only iterates the list once. This would probably be my solution if I was given this task in an interview. |