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;
    }
};
相关推荐
dialect_5 小时前
KMP算法
开发语言·c++·算法
reikocao6 小时前
卡尔曼滤波的动态机制:P如何改变融合权重
算法
总要学点什么6 小时前
第89篇:三维特效-螺旋圆效果——让螺旋臂卷起一圈圈外扩的涟漪
开发语言·javascript·ecmascript·webgl·cesium·空间分析·1024程序员节
漂流瓶jz6 小时前
UVA-1612 猜名次 题解答案代码 算法竞赛入门经典第二版
数据结构·算法·题解·排序·aoapc·算法竞赛入门经典
吞下星星的少年·-·7 小时前
Div.2 CF 1130B题(构造,贪心)
算法·贪心·构造
文丑颜不良啊7 小时前
LeetCode1481~1500题目解析
java·leetcode
ShineWinsu7 小时前
对于Qt:QRadioButton常见属性以及QButtonGroup的解析
数据库·c++·qt·microsoft·gui·qradiobutton·qbuttongroup
文丑颜不良啊7 小时前
LeetCode1381~1400题目解析
java·leetcode
傲世仙尊8 小时前
多态-虚表才活到运行期符号表早已消失
c++
开开心心_Every8 小时前
快速隐藏程序工具自定义快捷键一键切换
java·开发语言·前端·spring·智能手机·word·intellij-idea