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;
    }
};
相关推荐
地平线开发者9 分钟前
profiler debug 工具用法与高一致性策略
算法·自动驾驶
编程大师哥15 分钟前
匿名函数 lambda + 高阶函数
java·python·算法
isyangli_blog17 分钟前
OpenDayLight (Carbon 版本) 启动与组件安装
开发语言·php
vb20081125 分钟前
FastAPI APIRouter
开发语言·python
Benszen26 分钟前
KVM虚拟化解决方案
开发语言·perl
会编程的土豆28 分钟前
Go 语言反射(Reflection)详解
开发语言·后端·golang
東雪木30 分钟前
多线程与并发编程 专属复习笔记
java·开发语言·笔记·java面试
我叫袁小陌39 分钟前
算法解题思路指南
算法
MC皮蛋侠客42 分钟前
C++17 多线程系列(五):C++17 并行算法——从串行到并行的零成本迁移
c++·多线程
地平线开发者1 小时前
Conv+BN+Add+ReLU 融合机制简介
算法·自动驾驶