import java.util.HashSet;
import java.util.Set;
public class IsRepeated {
public static void main(String[] arg) {
System.out.println(isRepeated2(new int[] { 1, 2, 3, 4, 5, 5 }));
}
public static boolean isRepeated2(int[] nums) {
boolean flag = false;
Set<Integer> set = new HashSet<Integer>();
for(int i = 0; i < nums.length; i++) {
if(!set.add(nums[i])) {
flag = true;
break;
}
}
return flag;
}
}
有如果重复则返回true,否则返回false |