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;
    }
};
相关推荐
choumin2 小时前
创建型模式——工厂方法模式
c++·设计模式·工厂方法模式·创建型模式
云小逸2 小时前
【SVN 详细使用指南:从入门到团队协作】
c++·svn
互联网中的一颗神经元3 小时前
小白python入门 - 39. 采集流水线小项目
开发语言·python
徐小夕4 小时前
花了一周,3亿tokens,我开源了一款 Word 文档智能审查平台,文稿自动质检+可视化分析,告别低效人工审核
前端·算法·github
Wang's Blog4 小时前
Go-Zero 项目开发22:用户群聊功能的实现与完善
开发语言·golang
a1117764 小时前
坦克大战3D Three.js 3D (开源项目)
开发语言·javascript·3d
可编程芯片开发5 小时前
UPFC统一潮流控制器的simulink建模与仿真
算法
小小仙子5 小时前
矢量网络分析仪如何测试S参数的?
人工智能·算法·机器学习
Wang's Blog6 小时前
Go-Zero项目开发24: 基于Bitmap实现群聊消息已读未读
开发语言·后端·golang