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;
    }
};
相关推荐
Irissgwe7 小时前
二叉树进阶,map和set
数据结构·算法
Jackey_Song_Odd7 小时前
Part 1:Python语言核心 - 缩进与代码块
开发语言·python
郝学胜-神的一滴7 小时前
深度学习入门基石:PyTorch张量核心技术全解析
人工智能·pytorch·python·深度学习·算法·机器学习
@PHARAOH7 小时前
HOW - Go 开发入门(二)
开发语言·后端·golang
BUG?不,是彩蛋!7 小时前
从零到一掌握 K 线与技术指标:Java 实战教程 | MA, RSI, MACD 全解析
java·开发语言·spring boot·量化投资
Frostnova丶7 小时前
(10)LeetCode 560. 和为K的子数组
算法·leetcode·哈希算法
AI专业测评7 小时前
2026年AI写作软件底层技术全景解析:长篇AI写网文的工程化实践与AI消痕算法基准测试
人工智能·算法·ai写作
冰暮流星7 小时前
javascript之变量作用域
开发语言·前端·javascript
biter down7 小时前
C++ 设计不可被继承的类
java·开发语言·c++
Once_day7 小时前
C++之《程序员自我修养》读书总结(12)
c++·编译与链接