leetcode刷题,总结,记录,备忘 287
来源:互联网 发布:淘宝sku可以修改吗 编辑:程序博客网 时间:2024/05/16 04:02
leetcode287Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Note:
- You must not modify the array (assume the array is read only).
- You must use only constant, O(1) extra space.
- Your runtime complexity should be less than
O(n2)
. - There is only one duplicate number in the array, but it could be repeated more than once.
class Solution {public: int findDuplicate(vector<int>& nums) { set<int> si; for (vector<int>::iterator it = nums.begin(); it != nums.end(); ++it) { pair<set<int>::iterator, bool> p = si.insert(*it); if (p.second) { continue; } else { return *it; } } }};
0 0
- leetcode刷题,总结,记录,备忘 287
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- leetcode刷题,总结,记录,备忘83
- leetcode刷题,总结,记录,备忘70
- leetcode刷题,总结,记录,备忘 108
- iframe父子页面间通信总结
- 新人学ruby---通过ruby的net-ssh链接远程的服务器
- [茶聊] 项目准备阶段
- led灯
- prototype和__proto__
- leetcode刷题,总结,记录,备忘 287
- 黑窗口下带进度条的http下载
- Linux永久修改IP地址
- Android控件之WebView(基础知识)
- IOS开发:动画2 AlayerAnimation
- vs2012上跑起了python,甚至django
- 基于灰度的模板匹配算法(一):MAD、SAD、SSD、MSD、NCC、SSDA算法
- HDU 2639 Bone Collector II(01背包问题-第K优决策)
- Struts2 访问 Servlet API 的四种方式