首页 > 其他分享 >leetcode-217-easy

leetcode-217-easy

时间:2022-10-19 07:46:44浏览次数:49  
标签:217 set return int num easy leetcode

Contains Duplicate
思路一: Set 检测

public static boolean containsDuplicate(int[] nums) {
    Set<Integer> set = new HashSet<>();

    for (int num : nums) {
        if (set.contains(num)) {
            return true;
        }
        set.add(num);
    }
    
    return false;
}

标签:217,set,return,int,num,easy,leetcode
From: https://www.cnblogs.com/iyiluo/p/16804875.html

相关文章

  • leetcode-709-easy
    ToLowerCase思路一:遍历,遇到A-Z范围内的char转换到对应a-z范围publicStringtoLowerCase(Strings){if(s==null||s.isEmpty())returns;int......
  • leetcode-415-easy
    AddString思路一:模拟加法运算,字符串前面填零publicStringaddStrings(Stringnum1,Stringnum2){intmax=Math.max(num1.length(),num2.length());nu......
  • leetcode-389-easy
    FindtheDifference思路一:xor两个字符串publiccharfindTheDifference(Strings,Stringt){charresult=0;for(inti=0;i<s.length();i++){......
  • leetcode-226-easy
    InvertBinaryTree思路一:递归,交换左右。这题比较出名,个人感觉面试的题目和实际工作中遇到的问题还是不太一样的,所以一点准备都不做就跑去面试,答不上来很正常。一般能力......
  • leetcode-219-easy
    ContainsDuplicateII思路一:for循环遍历,结果超时publicbooleancontainsNearbyDuplicate(int[]nums,intk){intleft=-1;for(inti=0;i<nums......
  • leetcode-448-easy
    思路一:用数组记录publicList<Integer>findDisappearedNumbers(int[]nums){int[]m=newint[nums.length];for(intnum:nums){if(num-1......
  • leetcode-495-easy
    TeemoAttacking思路一:对两个前后攻击序列,完全分类只可能出现两种情况,只要把重叠的时间都减去,就是所求时间。此分类对三个以上的重叠时间依旧成立没有重叠,攻击时间累......
  • [LeetCode] 1700. Number of Students Unable to Eat Lunch
    Theschoolcafeteriaofferscircularandsquaresandwichesatlunchbreak,referredtobynumbers0and1respectively.Allstudentsstandinaqueue.Eachstu......
  • leetcode 380. Insert Delete GetRandom O(1) O(1) 时间插入、删除和获取随机元素 (
    一、题目大意实现RandomizedSet类:RandomizedSet()初始化RandomizedSet对象boolinsert(intval)当元素val不存在时,向集合中插入该项,并返回true;否则,返回false......
  • IDEA必备开发神器之EasyCode
    IDEA必备开发神器之EasyCode目录1、前言2、安装(EasyCode)3、建立数据库4、在IDEA配置连接数据库5、开始生成代码6、pom.xml7、Application.yml8、启动项目1、前......