Description

Given an array of integers, find if the array contains any duplicates.

Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

Example 1:

Input: [,,,]
Output: true

Example 2:

Input: [,,,]
Output: false

Example 3:

Input: [,,,,,,,,,]
Output: true

问题描述:给定一个数组,判断数组中是否存在重复元素,如果存在返回true,如果不存在返回false

思路:使用HashSet保存数组中的每个元素,如果在保存时HashSet中已经存在该元素,则返回true。

 public bool ContainsDuplicate(int[] nums) {
var hashSet = new HashSet<int>();
for(int i = ; i < nums.Length; i++){
if(hashSet.Add(nums[i])==false)
return true;
}
return false;
}

LeetCode Array Easy 217. Contains Duplicate的更多相关文章

  1. LeetCode Array Easy 219. Contains Duplicate II

    ---恢复内容开始--- Description Given an array of integers and an integer k, find out whether there are two ...

  2. LeetCode Array Easy 88. Merge Sorted Array

    Description Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted ar ...

  3. [LeetCode&Python] Problem 217. Contains Duplicate

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  4. LeetCode Array Easy 485. Max Consecutive Ones

    Description Given a binary array, find the maximum number of consecutive 1s in this array. Example 1 ...

  5. LeetCode Array Easy 448. Find All Numbers Disappeared in an Array

    Description Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear ...

  6. LeetCode Array Easy 414. Third Maximum Number

    Description Given a non-empty array of integers, return the third maximum number in this array. If i ...

  7. LeetCode Array Easy 283. Move Zeroes

    Description Given an array nums, write a function to move all 0's to the end of it while maintaining ...

  8. LeetCode Array Easy 268. Missing Number

    Description Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one th ...

  9. LeetCode Array Easy 189. Rotate Array

    ---恢复内容开始--- Description Given an array, rotate the array to the right by k steps, where k is non-ne ...

随机推荐

  1. 第二节 RabbitMQ配置

    原文:第二节 RabbitMQ配置 版权声明:未经本人同意,不得转载该文章,谢谢 https://blog.csdn.net/phocus1/article/details/87281553 1.配置 ...

  2. JS事件委托(事件代理,dom2级事件)

    一.前言 说实话,真问我什么是事件委托,我肯定gg,还好查了一下,原来就是我之前练习过的DOM2级事件的应用. 二.什么是事件委托? 事件委托就是当事件触发时,把要做的事委托给父元素(或父元素的父元素 ...

  3. dlib 基于摄像流检测眨眼次数

    眼睛纵横比(EAR) 在讨论EAR之前,先看看68个人脸特征点:  人脸特征点检测本身的算法是很复杂的,dlib中给出了相关的实现. 每只眼睛由6个(x,y)坐标表示,从眼睛的左角开始,然后围绕该区域 ...

  4. 【记录】iconfont 批量把图标加入购物车的方法

    iconfont  是阿里旗下很好用的图标管理网站(https://www.iconfont.cn/),里面有百万个小图标,可以随意下载切换颜色,是很多前端人员的选择. 但是网站没有将图标批量加入购物 ...

  5. 作业(二)—python实现wc命令

    Gitee地址:https://gitee.com/c1e4r/word-count(为什么老师不让我们用github) 0x00 前言 好久没发博客了,感觉自己的学习是有点偷懒了.这篇博客也是应专业 ...

  6. 转:动态库路径配置- /etc/ld.so.conf文件

    Linux 共享库 Linux 系统上有两类根本不同的 Linux 可执行程序.第一类是静态链接的可执行程序.静态可执行程序包含执行所需的所有函数 — 换句话说,它们是“完整的”.因为这一原因,静态可 ...

  7. 转载 Tomcat集群配置学习篇-----分布式应用

    Tomcat集群配置学习篇-----分布式应用 现目前基于javaWeb开发的应用系统已经比比皆是,尤其是电子商务网站,要想网站发展壮大,那么必然就得能够承受住庞大的网站访问量:大家知道如果服务器访问 ...

  8. 带你逐行阅读redux源码

    带你逐行阅读redux源码 redux版本:2019-7-17最新版:v4.0.4 git 地址:https://github.com/reduxjs/redux/tree/v4.0.4 redux目 ...

  9. python核心编程socket备忘

    服务器端: # Echo server program from socket import * from time import ctime HOST = '' # Symbolic name me ...

  10. 工具类Collections、Arrays(传入的是数组)

    Collections类: 1. Collections.sort(list)   //对list集合进行排序前提是 list里面存储的对象已经实现了 comparable接口 2. Collecti ...