1、题目描述

2、分析

利用C++的 标准模板库 set 对数组进行读取,然后插入,如果检测到元素已经在set内部,则返回该元素值即可。时间复杂度为 O(n),空间复杂度为 O(n);

3、代码

 int findDuplicate(vector<int>& nums) {
std::set<int> myset;
std::pair< std::set<int>::iterator,bool > ret; for( int i = ; i< nums.size(); i++)
{
ret = myset.insert( nums[i] );
if( ret.second == false )
{
return nums[i];
}
}
}

leetcode题解之Find the Duplicate Number的更多相关文章

  1. 【LeetCode】287. Find the Duplicate Number

    Difficulty:medium  More:[目录]LeetCode Java实现 Description Given an array nums containing n + 1 integer ...

  2. 【LeetCode】287. Find the Duplicate Number 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 保存已经访问过的数字 链表成环 二分查找 日期 题目 ...

  3. [LeetCode] Find the Duplicate Number 寻找重复数

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  4. LeetCode 287. Find the Duplicate Number (找到重复的数字)

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  5. [LeetCode 题解]:Palindrome Number

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Determine ...

  6. LeetCode 287. Find the Duplicate Number (python 判断环,时间复杂度O(n))

    LeetCode 287. Find the Duplicate Number 暴力解法 时间 O(nlog(n)),空间O(n),按题目中Note"只用O(1)的空间",照理是过 ...

  7. Leetcode之二分法专题-287. 寻找重复数(Find the Duplicate Number)

    Leetcode之二分法专题-287. 寻找重复数(Find the Duplicate Number) 给定一个包含 n + 1 个整数的数组 nums,其数字都在 1 到 n 之间(包括 1 和  ...

  8. [LeetCode] 287. Find the Duplicate Number 寻找重复数

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  9. [LeetCode] 287. Find the Duplicate Number(Floyd判圈算法)

    传送门 Description Given an array nums containing n + 1 integers where each integer is between 1 and n  ...

随机推荐

  1. 《Algorithms算法》笔记:优先队列(1)——API和初等实现

    1.优先队列的API和初等实现 做一个总结: 栈 :先进后出 队列 :先进先出 随机队列 : 随机出 优先队列:每次出来的是最大值或最小值 1.1优先队列的API 优先队列在很多场合都有用, 比如:在 ...

  2. SPSS学习系列之SPSS Modeler的功能特性(图文详解)

    不多说,直接上干货! Win7/8/10里如何下载并安装最新稳定版本官网IBM SPSS Modeler 18.0 X64(简体中文 / 英文版)(破解永久使用)(图文详解)   我这里,是以SPSS ...

  3. centos7 Mariadb5.5升级到Mariadb10.2

    一次升级过程,在此记录下. 原因:新的项目需要新的数据库版本支持. 升级主要步骤: 备份原数据库 --->卸载mariadb --->添加mariadb国内yum源 --->安装ma ...

  4. linux环境下编译C++ 程序

    GCC(GNU Compiler Collection)是Linux下最主要的编译工具,GCC不仅功能非常强大,结构也异常灵活.它可以通过不同的前端模块来支持各种语言,如:Java.Fortran.P ...

  5. Linux的MySQL不能远程访问

    1.首先,你要确认用户是否只允许localhost访问: 在linux下登录mysql mysql -uroot -p密码;     use mysql;     select `host`,`use ...

  6. Java并发编程笔记之LongAdder和LongAccumulator源码探究

    一.LongAdder原理 LongAdder类是JDK1.8新增的一个原子性操作类.AtomicLong通过CAS算法提供了非阻塞的原子性操作,相比受用阻塞算法的同步器来说性能已经很好了,但是JDK ...

  7. mysql中难以理解的sql

    工作中遇到这样的例子, CASE type WHEN 1 THEN '普通红包' WHEN 2 THEN '普通礼包加油卡' WHEN 3 THEN '优 惠码兑换加油卡' WHEN 4 THEN ' ...

  8. Spring的@Scheduled任务调度

    一. 定时任务实现方式 定时任务实现方式: Java自带的java.util.Timer类,这个类允许你调度一个java.util.TimerTask任务.使用这种方式可以让你的程序按照某一个频度执行 ...

  9. DAO设计模式(转)

    J2EE开发人员使用数据访问对象(DAO)设计模式把底层的数据访问逻辑和高层的商务逻辑分开.实现DAO模式能够更加专注于编写数据访问代码. 我们先来回顾一下DAO设计模式和数据访问对象. DAO基础  ...

  10. POJ 1251 Jungle Roads(Kruskal算法求解MST)

    题目: The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money w ...