码迷,mamicode.com
首页 > 其他好文 > 详细

217. Contains Duplicate

时间:2018-04-13 15:13:36      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:bsp   array   解题思路   tar   size   solution   als   alt   nbsp   

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.

 解题思路:

用散列是可以的,这里用set熟悉一下set的用法,可以删掉重复数据,不过复杂度会高点。set用了二叉树结构

  1. class Solution {  
  2. public:  
  3.     bool containsDuplicate(vector<int>& nums) {  
  4.         set<int> test(nums.begin(),nums.end());  
  5.         if(test.size()<nums.size()) return true;  
  6.         else return false;  
  7.     }  
  8. };  

217. Contains Duplicate

标签:bsp   array   解题思路   tar   size   solution   als   alt   nbsp   

原文地址:https://www.cnblogs.com/liangyc/p/8820230.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!