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;
    }
};
相关推荐
Zachery Pole2 小时前
CCF-CSP备战NO.5链表(1)
数据结构·链表
Wang's Blog2 小时前
Go-Zero 项目开发43:基于 Filebeat 收集各个服务的日志信息
开发语言·golang·go-zero·filebeat
丈剑走天涯4 小时前
JDK 17 正式特性
java·开发语言
秋田君4 小时前
QT_QFontDialog类字体对话框
开发语言·qt
圣光SG4 小时前
Java操作题练习(七)
java·开发语言·算法
麻瓜老宋5 小时前
AI开发C语言应用按步走,表达式计算器calc的第二十三步,多行输入、进制输出、错误恢复、常量折叠、配置加载等
c语言·开发语言·atomcode
Cx330_FCQ5 小时前
Tmux使用
服务器·git·算法
q567315235 小时前
企业级 HTTP 代理采购选型:技术评估清单 15 项
开发语言·网络·爬虫·网络协议·http·隧道ip·代理ip
天天进步20156 小时前
Python全栈项目--智能办公自动化系统
开发语言·python
拳里剑气6 小时前
C++算法:多源BFS
c++·算法·宽度优先·多源bfs