Hello there,
Given an array int a[] = {10,11,12,13,10,11}. I want to print out the unique elements and the count of duplicates in this array.
Can someone help me find this. I am kind of stuck in the logic.
Thanks,
-R
Printable View
Hello there,
Given an array int a[] = {10,11,12,13,10,11}. I want to print out the unique elements and the count of duplicates in this array.
Can someone help me find this. I am kind of stuck in the logic.
Thanks,
-R
Some psuedo...
I suspect there are quite a few classes you may be able to use for your operations if the specifications of your program are not limited to just a regular array. ArrayList comes to mind.Code:1) read the array and have method available for searching the array
a) if a number matches any other number
- mark it for non-printable
- increase the counter
2) Output the printable number and the counter
You can use the Set (HashSet) class to remove the duplicate items in the array.
1. Create an array
2. Convert it to a List
3. Create a Set from the List
4. When you get the set, convert it back to array.
After the step you'll have the duplicate element removed from the list.