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;
    }
};
相关推荐
一只专注api接口开发的技术猿几秒前
OpenClaw 对接淘宝商品 API,低成本实现全天候选品监控|附可运行 Python 实操代码
大数据·开发语言·数据库·python
xingpanvip2 分钟前
星盘接口开发文档:马盘次限盘接口指南
android·开发语言·python·php·lua
FBI HackerHarry浩3 分钟前
第二阶段Day07【Python生成器、yield关键字、property、正则表达式】
开发语言·python·正则表达式
iiiiyu11 分钟前
IO流(二)
java·开发语言·数据结构·编程语言
白露与泡影11 分钟前
牛客网大厂Java面试题全集(2026版,附答案)
java·开发语言
零点一顿微胖16 分钟前
[Agent]实现获取系统基本信息接口 Rust版
开发语言·rust
折戟不必沉沙18 分钟前
构造和析构函数能否是虚函数?能否调用虚函数?
c++
leo__52032 分钟前
随机接入退避算法过程模拟实现
网络·算法
Java面试题总结33 分钟前
AgentScope Harness 深度实战:让Java智能体从“Demo可用”走向“生产可用”
java·开发语言·wpf
-To be number.wan35 分钟前
算法日记 | STL- sort排序
c++·算法