3 ms·
You could add a dublicate counter. Once out find a pair, let j increase until numbers[j] != numbers[j+1] and count how many duplicates you encounter. Add this n
by 0xB504 9y ago
You could add a dublicate counter.
Once out find a pair, let j increase until numbers[j] != numbers[j+1] and count how many duplicates you encounter. Add this number to pairs everytime you find one. Once you increase j set the duplicate counter back to one.