Answer the question
In order to leave comments, you need to log in
What's wrong with the algorithm?
Good afternoon, the tester shows supposedly incorrect. What's wrong?
Task:
The program receives a large number of integers as input. All numbers except one have a pair, and there may be several identical pairs. Find a number without a pair.
def test(a):
for index,n in enumerate(a):
if(a.count(n)%2!=0):
return n
a=[1,1,2,2,3,3,4,4,5,5,6,6,7,7,1]
print(test(a))
Answer the question
In order to leave comments, you need to log in
the tester shows supposedly incorrectMost likely, you are not on time. Now your algorithm is very suboptimal - in the worst case, you do n 2 iterations over the array (count must also somehow calculate the values). Since the text of the problem specifically specifies a large number of numbers, it is understood that the algorithm will be as non-greedy as possible in terms of resources.
- `enumerate(a)` creates a copy of the field
- `arr` is not used at all
- `test` function may be isolated from `a`
- `index` is not used
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question