Skip to content

Instantly share code, notes, and snippets.

@dhicksNTIA
dhicksNTIA / cloudSettings
Last active May 9, 2018 20:47
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-05-09T20:47:08.023Z","extensionVersion":"v2.9.2"}
/// Find first duplicate integer in vector.
///
/// Assumed that array a contains only number in range [1, a.len()].
/// O(n) time complexity and O(1) memory. NOT PURE FUNCTIONAL.
///
/// # Example
///
/// ```
/// assert!(first_duplicate(vec![8, 4, 6, 2, 6, 4, 7, 9, 5, 8]) == 6);
/// assert!(first_duplicate(vec![2, 1, 4, 5, 3]) == -1);