LeetCode217. Contains Duplicate

文章目录

一、题目

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Example 1:

Input: nums = [1,2,3,1]

Output: true

Example 2:

Input: nums = [1,2,3,4]

Output: false

Example 3:

Input: nums = [1,1,1,3,3,4,3,2,4,2]

Output: true

Constraints:

1 <= nums.length <= 105

-109 <= nums[i] <= 109

二、题解

cpp 复制代码
class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        unordered_map<int,int> map;
        for(auto x:nums){
            if(map[x] == 1) return true;
            map[x]++;
        }
        return false;
    }
};
相关推荐
rit84324994 分钟前
人工鱼群算法AFSA优化支持向量机SVM,提高故障分类精度
算法·支持向量机·分类
Bellafu66612 分钟前
项目中遇到pom文件里使用systemPath的例子记录
开发语言
爱喝水的鱼丶22 分钟前
SAP-MM:SAP采购组织全面学习指南:从概念到实战配置图解
运维·开发语言·数据库·学习·sap·mm模块·采购组织
楼田莉子26 分钟前
Python学习——字典和文件
开发语言·python·学习·pycharm
佩佩(@ 。 @)28 分钟前
嵌入式:走馬燈-stm32GPIOF_LED9、10; GPIOE_D10、D12 流水綫蜂鸣器
stm32·嵌入式硬件·算法
知彼解己34 分钟前
字符串大数相加:从初稿到优化的思路演进
java·开发语言·算法
染指111038 分钟前
11.ImGui-加载字体和中文
c++·windows·imgui
好多1740 分钟前
《JVM如何排查OOM》
开发语言·jvm·python
学计算机的1 小时前
Python:OpenCV 教程
开发语言·python
拾忆,想起1 小时前
Redisson 分布式锁的实现原理
java·开发语言·分布式·后端·性能优化·wpf