Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int firstDuplicate(int[] a) {
- object[] values = new object[a.Length];
- for (int i = 0, idx; i < a.Length; i++)
- if (values[idx = a[i] - 1] == null) values[idx] = new object();
- else return ++idx;
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement