package 劍指offer_初級;
import java.util.HashSet;
import java.util.Set;
public class 劍指_Offer_03_數組中重複的數字 {
class Solution {
public int findRepeatNumber(int[] nums) {
for(int i=0;i<nums.length;i++){
for(int j=i+1;j<nums.length;j++){
if(nums[i]==nums[j]){
return nums[i];
}
}
}
return -1;
}
public int findNumber(int[] nums) {
Set<Integer> dic = new HashSet<>();
for(int num : nums) {
if(dic.contains(num)){return num;}
dic.add(num);
}
return -1;
}
}
}