Skip to content

Instantly share code, notes, and snippets.

View luangong's full-sized avatar

Luan Gong luangong

View GitHub Profile
@ruoguluo
ruoguluo / FindDuplicate.java
Created February 3, 2017 06:25
Find the duplicated number in an array of length N
public class FindDuplicate {
public static void main(String[] args) {
FindDuplicate fd = new FindDuplicate();
int[] nums = new int[]{1, 2, 3, 4, 5, 6, 1};
assert (fd.find(nums) == 1);
nums = new int[]{1, 2, 3, 4, 5, 6, 1};
assert (fd.find(nums) == 1);
nums = new int[]{2, 2, 3, 4, 5, 6, 1};
assert (fd.find(nums) == 2);