+ 2
Program to remove duplicate elements in an array in C
I want to code a program which takes about 10000 numbers which maybe duplicated, I want to remove the duplicated numbers and then add them up but I would have runtime exceed, How can I do that in C language?
5 Respostas
+ 4
ahhh....thought.....qsort() first then.........instead of having a second array....if current == next, replace current with a 0 (zero) in the same array then loop through to do the sum. Again, no idea how long it would take.
Is removing the duplicates the main objective or are you just trying to get sum of the none duplicates?
+ 3
HonFu Actually I have to code for somewhere and they had made this time limitation.
Im looking for another way to solve this problem instead fo using nested for
+ 3
You could use qsort() to sort them, then... in a single loop, check if the current is equal to next......if it isn't...... put the current into second array..(but I have no ideal how long that would take)....then loop through the second array to do the sum.
(still thinking about it thought.)
+ 2
Runtime exceeded is a Sololearn issue because the runtime for every code here is limited to a few seconds.
Did you try the same code on your computer?
+ 2
rodwynnejones haven’t heard about qsort() function
Really interesting.
Your opinion about making the duplicated ones to zero was awesome
Thank you so much🙏😊
I’ll try that