LeetCode Array Easy 217. Contains Duplicate
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: trueExample 2:
Input: [,,,]
Output: falseExample 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的更多相关文章
- LeetCode Array Easy 219. Contains Duplicate II
---恢复内容开始--- Description Given an array of integers and an integer k, find out whether there are two ...
- LeetCode Array Easy 88. Merge Sorted Array
Description Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted ar ...
- [LeetCode&Python] Problem 217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- LeetCode Array Easy 485. Max Consecutive Ones
Description Given a binary array, find the maximum number of consecutive 1s in this array. Example 1 ...
- 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 ...
- 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 ...
- 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 ...
- LeetCode Array Easy 268. Missing Number
Description Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one th ...
- LeetCode Array Easy 189. Rotate Array
---恢复内容开始--- Description Given an array, rotate the array to the right by k steps, where k is non-ne ...
随机推荐
- matploylib之热力图
刚学我也不熟,做个笔记吧 # coding:utf-8 import numpy as np import matplotlib.pyplot as plt dx = 0.01 dy = 0.01 # ...
- IIS Express 不允许的父路径
IIS Express 启动一个asp的网站,出现一个错误 Active Server Pages 错误 'ASP 0131' 不允许的父路径 对于IIS可以在可视化的IIS Manager中配置: ...
- 图片查看器(类似于QQ,另外又加了JARA的下方的图片缩略导航图)
源码地址:https://gitee.com/yolanda624/coffer/tree/master/src/components/a-photo-view
- DataX简介
DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL.Oracle.SqlServer.Postgre.HDFS.Hive.ADS.HBase.TableStore(O ...
- Linux拓展练习部分--输入输出 / find部分 /基础拓展2
目录 输入输出部分 find部分 基础阶段-拓展练习2 输入输出部分 1.输入时间命令"date"将当前系统时间输出到/data/1.txt [root@centos7 ~]# d ...
- Rxjava Retrofix2 okhttp3网络框架自解(转)
直接代码 类一 public class Okhttp3Utils { private static OkHttpClient mOkHttpClient; public static OkHttpC ...
- excel acm 高校排名(hdoj)
其实写一个程序是最方便的... 不用每次进行很多次操作. 当然,能获得后台的数据更好…… e.g. 链接: https://pan.baidu.com/s/1a7s85oaKGam1-0mJ2v39u ...
- pywin3的简介
微软Windows的Python扩展提供了对Win32 API的访问.创建和使用COM对象的能力以及PythOnWin环境.Pywin32是一个Python库,为python提供访问Wind ...
- 开放融合 | “引擎级”深度对接!POLARDB与SuperMap联合构建首个云原生时空平台
阿里巴巴新一代自研云数据库POLARDB与超图软件SuperMap GIS实现 “引擎级”深度对接,构建了自治.弹性.高可用的云原生时空数据管理平台联合解决方案,推出了业界首个“云原生数据库+云原生G ...
- SCP-bzoj-3309
项目编号:bzoj-3309 项目等级:Safe 项目描述: 戳这里 特殊收容措施: 以下用\((x, y)\)表示\(gcd(x, y)\). \[ ans = \sum _ {i = 1} ^ { ...