Love丶FFC's Blog
给定一个整数数组,查找数组是否包含任何重复项。 如果数组中某个值至少出现两次,则函数应返回true,如果每个元素都是不同的,则返回false。
样例 1:
输入:nums = [1, 1]
输出:True
样例 2:
输入:nums = [1, 2, 3]
输出:False
1.使用Hashset来判断第一个元素的情况。
2.使用枚举法来判断是否还存在一个元素相同。
3.使用boolean来判断结果。
package LintCode_Easy; import java.util.HashSet; public class _1320 { public static void main(String[] args) { int[] nums = new int[] {1,2,3}; HashSet<Integer> hashSet = new HashSet<Integer>(); boolean containsDuplicate = false; for(int i=0;i<nums.length;i++) hashSet.add(nums[i]); for(int i=0;i<nums.length;i++) { if(hashSet.contains(nums[i])) //存在一个相同元素 { for(int j=i+1;j<nums.length;j++) //从剩余元素中判断是否还存在一个相同元素 { if(nums[j]==nums[i]) { containsDuplicate=true; break; } } } } System.out.println(containsDuplicate); } }
public class Solution { public boolean containsDuplicate(int[] nums) { HashSet<Integer> hashSet = new HashSet<Integer>(); boolean containsDuplicate = false; for(int i=0;i<nums.length;i++) hashSet.add(nums[i]); for(int i=0;i<nums.length;i++) { if(hashSet.contains(nums[i])) //存在一个相同元素 { for(int j=i+1;j<nums.length;j++) //从剩余元素中判断是否还存在一个相同元素 { if(nums[j]==nums[i]) { containsDuplicate=true; break; } } } } return containsDuplicate; } }
FoorryNox
The common marmoset, a New World monkey, has a primate specific cortex with approximately 40 Brodmann areas buy cialis online no prescription
Preliaf
You might try eye drops or even glasses with thick rims so you don t notice the shadow as much viagra patent expiration About 25 also used AIs about half of those taking them with tamoxifen and half without, for a median time period of between 2 and 3 years, according to the report
LMHLJoAfr
finpecia fast delivery overnight The International Society for Magnetic Resonance in Medicine and the Roger E