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. PHP CURL 抓取失败 自己调试

    蛋疼的一下午,物理机win7旗舰版+APACHE2 ,CURL抓取一直成功. 虚拟机ubuntu+apache2一直抓取失败. 晚上,问个仁兄才知道,CURL可以调试: 参考这位兄台: 地址 curl ...

  2. python独立环境——virtualenv

    安装: pip3 intall virtualenv   创建独立运行环境: 1. 进入项目文件夹根目录 2. 创建环境 Mac:myproject michael$ virtualenv --no- ...

  3. android GridLayout布局

    android4.0版本后新增了一个GridLayout,它使用虚细线将布局划分为行.列和单元格,也支持一个控件在行.列上都有交错排列,其实用方法和LinearLayout,Relativelayou ...

  4. Android 开发服务类 02_NewsListServlet

    Servlet implementation class NewsListServlet package com.wangjialin.server.xml; import java.io.IOExc ...

  5. AndroidStudio生成自己的Compile依赖

    在AndroidStudio中经常使用compile的方式来导入第三方代码,如图所示: 想要拥有自己的依赖,可参考本篇的方法 在github上托管一个带有Android Libray的项目,我们要co ...

  6. Chapter 3 Phenomenon——10

    It took six EMTs and two teachers — Mr. Varner and Coach Clapp — to shift the van far enough away fr ...

  7. glide 解决 golang.org/x/net 等依赖包无法获取

    知道glide有设置镜像功能,可以把某个依赖包的源地址切换为另一个地址,相当于切换到镜像地址,用于某些依赖包被墙的原因 之前碰到 golang.org/x/net,设置镜像: glide mirror ...

  8. cookie和session的区别,session的生命周期,

    这些都是基础知识,不过有必要做深入了解.先简单介绍一下. 二者的定义: 当你在浏览网站的时候,WEB 服务器会先送一小小资料放在你的计算机上,Cookie 会帮你在网站上所打的文字或是一些选择, 都纪 ...

  9. It is likely that the remote side declared peer gone on this JVM

    java.net.ConnectException: t3://host:port: Bootstrap to host/host:port failed. It is likely that the ...

  10. 记laravel5.5项目php-fpm迁移到swoole4.2.9

    事起说明 最近对上线半年多的laravel项目做了一次少大的改动,由php-fpm改为swoole,这里做个记录. 2019年过年前半个月,上阿里云后台查看前一天的访问请求日志,发现很多接口响应慢.翻 ...