首页 > 学院 > 开发设计 > 正文

217. Contains Duplicate

2019-11-08 02:11:25
字体:
来源:转载
供稿:网友

题目

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

Subscribe to see which companies asked this question.


思路

用set存,再看大小是否变小,一行代码搞定


代码

class Solution {public: bool containsDuplicate(vector<int>& nums) { return nums.size() > set<int>(nums.begin(),nums.end()).size(); }};
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表