Created
October 9, 2018 17:25
-
-
Save davidbreyer/bf666204ffca41a8e19516ecd2d5a260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int firstDuplicate(int[] a) { | |
for (int i = 0; i < a.Length; i++) { | |
if (a[Math.Abs(a[i])-1] >= 0) | |
a[Math.Abs(a[i])-1] = -a[Math.Abs(a[i])-1]; | |
else | |
return Math.Abs(a[i]); | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment