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;
    }
};
相关推荐
米粒114 小时前
力扣算法刷题 Day 42(股票问题总结)
算法·leetcode·职场和发展
zopple15 小时前
汇编、C、C++和Java核心技术对比
c语言·汇编·c++
kaikaile199515 小时前
C# 文件编码转换工具
开发语言·c#
汉克老师15 小时前
GESP2024年3月认证C++三级( 第三部分编程题(1、字母求和)
c++·string·gesp三级·gesp3级·大小写判断
沐雪轻挽萤15 小时前
10. C++17新特性-保证的拷贝消除 (Guaranteed Copy Elision / RVO)
开发语言·c++
河阿里15 小时前
Java-JWT令牌技术深度指南
java·开发语言
leaves falling16 小时前
C/C++ 的内存管理,函数栈帧详讲
java·c语言·c++
文静小土豆16 小时前
Java 应用上 K8s 全指南:从部署到治理的生产级实践
java·开发语言·kubernetes
wuyoula16 小时前
AI导航智能决策系统源码 附教程
c++·tcp/ip·源码
西西弗Sisyphus16 小时前
Python 在终端里彩色打印
开发语言·python·print·彩色打印