LeetCode(217)Contains Duplicate
2024-09-03 15:11:25
题目
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.
分析
判断所给整数序列中有无重复元素。
AC代码
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
if (nums.empty())
return false;
unordered_set<int> us;
int len = nums.size();
for (int i = 0; i < len; ++i)
{
if (us.count(nums[i]) != 0)
return true;
else
us.insert(nums[i]);
}
return false;
}
};
最新文章
- win7,ubuntu双系统——重装win7后如何恢复ubuntu引导
- php启动时候提示PHP startup的解决方法
- xampp 提示 This setting can be configured in the file ";httpd-xampp.conf";.
- Educational Codeforces Round 4 B. HDD is Outdated Technology 暴力
- Servlet &; JSP - Servlet API Overview
- android颜色对应的xml配置值,颜色表
- JAVA 泛型练习
- win10系统加载ahci驱动的操作方案(Win10之家)
- 201521123010 《Java程序设计》第5周学习总结
- html5开发学习 html5自学需要怎么学
- mystricpy的实现???
- img图片占不满整个div
- web 基础设置
- asp.net core系列 36 WebAPI 搭建详细示例
- 从零开始学安全(三十六)●利用python 爆破form表单
- Http协议Status状态代码
- 【2016.3.19】作业 分析一个很有(wu)趣(liao)的小程序
- redis源码学习-skiplist
- ory Oathkeeper Ecosystem
- Apache服务器的简单配置与安全策略