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;
    }
};
相关推荐
q5673152315 分钟前
分布式增量爬虫实现方案
开发语言·分布式·爬虫·python
勤奋的知更鸟21 分钟前
LLaMA-Factory和python版本的兼容性问题解决
开发语言·python·llama-factory
CIb0la23 分钟前
Ai自动补全编程工具:llama vscode
运维·开发语言·学习·测试工具·程序人生
1candobetter33 分钟前
JAVA后端开发——多租户
java·开发语言
freyazzr1 小时前
C++八股 | Day3 | 智能指针 / 内存管理 / 内存分区 / 内存对齐
开发语言·c++
蒟蒻小袁1 小时前
力扣面试150题--课程表
算法·leetcode·面试
闻缺陷则喜何志丹1 小时前
【动态规划】B4336 [中山市赛 2023] 永别|普及+
c++·算法·动态规划·洛谷
序属秋秋秋1 小时前
《C++初阶之入门基础》【普通引用 + 常量引用 + 内联函数 + nullptr】
开发语言·c++·笔记
星辰离彬1 小时前
Java 高级泛型实战:8 个场景化编程技巧
java·开发语言·后端·程序人生