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;
    }
};
相关推荐
码匠许师傅7 小时前
【C++三方组件】cxxopts:轻量首选的命令行解析
c++
金金计较.7 小时前
Go语言-4
开发语言·golang
hansang_IR7 小时前
【讲解】CSP-S2026 第一轮初赛
c++·算法
hanlin037 小时前
刷题笔记:力扣第76题-最小覆盖子串
笔记·算法·leetcode
Zane19947 小时前
比较排序跑不出O(nlogn)是数学上证明过的,计数、桶、基数排序凭什么能绕开这堵墙
算法·排序算法
tiger8657 小时前
大语言模型面试和题解,梳理中国主流开源 LLM 系列的发展脉络、技术路线与工程取舍
人工智能·gpt·深度学习·算法·自然语言处理·面试·transformer
Methy7 小时前
IoTHub半个月崩了五次?都是裸rethrow惹的祸
服务器·c++·后端
泡海椒7 小时前
jquick-pdf 表格行列尺寸控制实战:单元格合并的可行边界
java·开发语言·pdf
我不会起名字3228 小时前
一天一道力扣Hot100(36):深度优先算法---组合总和
数据结构·c++·后端·python·算法·go
纪念 2298 小时前
c++类和对象(四)
开发语言·c++