k*t
1 楼
If you have numbers in a 10,000 item array that range from 1 to 1 million,
and there is one duplicate. How do you find the duplicate with the simplest
algorithm?
我想到一种方法是从左到右,对每一个数字扫描其之后的数字。
另一种方法是用一个set,从左到右依次往set里面加,set.contains(...)来判断是否
是重复。
请问,有没有更好的方法?
and there is one duplicate. How do you find the duplicate with the simplest
algorithm?
我想到一种方法是从左到右,对每一个数字扫描其之后的数字。
另一种方法是用一个set,从左到右依次往set里面加,set.contains(...)来判断是否
是重复。
请问,有没有更好的方法?