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 <= numsi <= 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;
    }
};
相关推荐
KaMeidebaby6 分钟前
卡梅德生物技术快报|抗体合成:多肽抗体合成工程化方案:Nsp2 保守肽多抗制备与多维度验证
前端·网络·数据库·人工智能·算法
没钥匙的锁132 分钟前
05-Java面向对象构造器与封装
java·开发语言
仙人球部落35 分钟前
-python-LangGraph框架(3-31-LangGraph 「合并式状态管理」的原理与实践)
开发语言·javascript·python
2401_8949155338 分钟前
Geo搜索优化排名源码部署搭建全流程详解
android·开发语言·flask·php·精选
Yang_jie_031 小时前
笔记:数据结构(栈是否使用底指针以及头指针的初始化值)
数据结构·笔记·算法
aaPIXa6221 小时前
C++采样引导优化SPGO——比PGO更智能的编译器决策新方案
java·c++·人工智能
2301_800895101 小时前
信息安全数学基础复习
算法
爱折腾的小黑牛1 小时前
简记往来批量录入功能的实现:从文本到结构化数据
前端·算法
chouchuang1 小时前
day-025-面向对象-上
开发语言·python
Starmoon_dhw1 小时前
题解:P17078 夏日甜点
c++·学习·算法·图论