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;
    }
};
相关推荐
格林威3 分钟前
工业相机“心跳”监测脚本(C# 版) 支持海康 / Basler / 堡盟工业相机
开发语言·人工智能·数码相机·opencv·计算机视觉·c#·视觉检测
小苗卷不动3 分钟前
OJ练习之加减(中等偏难)
c++
闲人xyz4 分钟前
02|Tool Runtime 不是工具箱,而是行动层:从 FileRead / FileEdit 看到 Agent 工程
算法
我能坚持多久5 分钟前
String类常用接口的实现
c语言·开发语言·c++
自我意识的多元宇宙9 分钟前
二叉树的遍历和线索二叉树--由遍历序列构造二叉树
数据结构
花间相见9 分钟前
【大模型微调与部署03】—— ms-swift-3.12 命令行参数(训练、推理、对齐、量化、部署全参数)
开发语言·ios·swift
AI专业测评9 分钟前
2026网文圈大地震:顶配AI写作神器实测,这几款让“代练”彻底失业
人工智能·算法·aigc·ai写作
智者知已应修善业11 分钟前
【数字稳压控制DAC/TLC5615驱动】2023-5-27
c++·经验分享·笔记·算法·51单片机
爱写代码的倒霉蛋12 分钟前
2021年天梯赛L1-8
数据结构·算法
默 语12 分钟前
Java的“后路“:不是退场,而是换了一种活法
java·开发语言·python