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;
    }
};
相关推荐
qwert10372 分钟前
深入解析Python标识符:定义、规则、规范与实践指南
开发语言·数据库·python
cqwuliu9 分钟前
Freemarker模板工具
java·开发语言
学习,学习,在学习9 分钟前
Qt多线程的使用与注意事项
开发语言·数据库·qt
asdfg125896310 分钟前
`(line1, line2) -> line1 + line2` 此Lambda 表达式的理解
java·开发语言
吃着火锅x唱着歌10 分钟前
LeetCode 739.每日温度
算法·leetcode·职场和发展
如竟没有火炬12 分钟前
去除重复字母——贪心+单调栈
开发语言·数据结构·python·算法·leetcode·深度优先
小侯不躺平.17 分钟前
C++ Boost库【4】 --分词器的使用
c++·windows·microsoft
AI人工智能+电脑小能手20 分钟前
【大白话说Java面试题 第49题】【JVM篇】第9题:什么是双亲委派机制?介绍一下运作过程。?
java·开发语言·jvm
薛定e的猫咪22 分钟前
【ICML 2025】MODULI:基于扩散模型解锁离线多目标强化学习的偏好泛化
人工智能·学习·算法·机器学习
码农-阿杰23 分钟前
Java 线程中断机制深度解析:从 API 到底层 C++ 实现
java·开发语言·c++