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;
    }
};
相关推荐
songroom6 小时前
Kimi K3:Rust封装XTP接口详细教程实践
开发语言·后端·rust
kebeiovo6 小时前
游戏服务端开发:Actor模型详解(Go语言)
开发语言·后端·golang
ChaoZiLL6 小时前
我的数据结构4-栈和队列
数据结构
香辣牛肉饭6 小时前
【算法】动态规划 最长公共子序列(LCS)
经验分享·笔记·算法·动态规划
迷途呀7 小时前
Python:函数中的参数类型
开发语言·笔记·python·langchain·nlp
miller-tsunami7 小时前
顺序表相关知识点
数据结构·顺序表
Herbert_hwt7 小时前
建立Java程序开发
java·开发语言
愚公移码7 小时前
蓝凌EKP18产品:流程虚拟机(PVM)
java·开发语言·前端
.徐十三.7 小时前
一篇文章看到最短路径——Dijkstra算法
算法