Increment duplicate elements | SoloLearn: Learn to code for FREE!

+7

Increment duplicate elements

how to create a method to increment all duplicate element expect the first in a sorted array until obtain an array without any duplication items for example array={1,2,3,3,4,4} the solution: like this array={1,2,3,4,4,4} array={1,2,3,4,5,4} array={1,2,3,4,5,5} array={1,2,3,4,5,6}

2/25/2018 7:50:24 PM

Zeyad Sharo

1 Answer

New Answer

+2

bool success = false; while(!success) { success = true; foreach(int n in [array]) { if([array].Contains(n)) { n++; success = false; } } something like this? ;) replace [array] with the name of your array. Syntax errors might be included.