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;
    }
};
相关推荐
英英_13 小时前
MATLAB数值计算基础教程
数据结构·算法·matlab
一起养小猫13 小时前
LeetCode100天Day14-轮转数组与买卖股票最佳时机
算法·leetcode·职场和发展
至为芯13 小时前
IP6537至为芯支持双C口快充输出的45W降压SOC芯片
c语言·开发语言
hele_two13 小时前
快速幂算法
c++·python·算法
OopspoO14 小时前
C++杂记——Name Mangling
c++
yuanmenghao14 小时前
车载Linux 系统问题定位方法论与实战系列 - 车载 Linux 平台问题定位规范
linux·运维·服务器·网络·c++
小羊羊Python14 小时前
SoundMaze v1.0.1正式发布!
开发语言·c++
浩瀚地学14 小时前
【Java】JDK8的一些新特性
java·开发语言·经验分享·笔记·学习
l1t14 小时前
利用DeepSeek将python DLX求解数独程序格式化并改成3.x版本
开发语言·python·算法·数独
jllllyuz14 小时前
基于子集模拟的系统与静态可靠性分析及Matlab优化算法实现
算法·matlab·概率论