+ 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}

25th Feb 2018, 7:50 PM
Zeyad Sharo
Zeyad Sharo - avatar
1 Resposta
+ 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.
25th Feb 2018, 11:12 PM
Kai Schlegel
Kai Schlegel - avatar