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;
    }
};
相关推荐
ptc学习者几秒前
python 中描述符@property property 大概的样子
开发语言·python
zmzb01032 分钟前
Python课后习题训练记录Day129
开发语言·python
洛水水5 分钟前
【力扣100题】81.寻找两个正序数组的中位数
数据结构·算法·leetcode
张忠琳10 分钟前
【Go 1.26.4】Golang Map 深度解析
开发语言·后端·golang
Vertira11 分钟前
如何对QT开发的软件进行打包[已解决]
开发语言·qt
AI人工智能+电脑小能手13 分钟前
【大白话说Java面试题 第110题】【并发篇】第10题:CAS 存在哪些问题?
java·开发语言·面试
石一峰69921 分钟前
C 语言函数设计模式实战经验
c语言·开发语言·设计模式
sitellla27 分钟前
Pydub:用 Python 处理音频,不写废话
开发语言·python·其他·音视频
happymaker062634 分钟前
LeetCodeHot100——155.最小栈
算法
xingyuzhisuan36 分钟前
缓存命中率提升方案:从 30% 优化至 82% 全流程优化记录
java·开发语言·缓存·ai