【leetcode】First Missing Positive
来源:互联网 发布:网络歌曲牛什么牛 编辑:程序博客网 时间:2024/05/19 04:26
【leetcode】First Missing Positive
找第一个没有出现的正数,我感觉很简单啊,为什么是hard?我打算用一个数组把正数作为下表映射到数组中。然后么,直接遍历数组,找到第一个没出现的就ok。
class Solution {public: int firstMissingPositive(vector<int>& nums) { if(nums.size()==0) return 1; bool *res; res=new bool[nums.size()+2]; memset(res,false,nums.size()+2); for(unsigned int nIndex=0;nIndex<nums.size();++nIndex) if(nums[nIndex]>0) res[nums[nIndex]]=true; for(unsigned int nIndex=1;nIndex<nums.size()+2;++nIndex) if(res[nIndex]==false) { delete res; return nIndex; } delete res; return 1; }};
0 0
- LeetCode: First Missing Positive
- LeetCode First Missing Positive
- LeetCode: First Missing Positive
- [Leetcode] First Missing Positive
- [LeetCode] First Missing Positive
- [Leetcode] First Missing Positive
- leetcode First Missing Positive
- LeetCode First Missing Positive
- [leetcode] first missing positive
- LeetCode: First Missing Positive
- [LeetCode]First Missing Positive
- LeetCode-First Missing Positive
- [leetcode] First Missing Positive
- [LeetCode] First Missing Positive
- LeetCode - First Missing Positive
- LeetCode | First Missing Positive
- Leetcode: First Missing Positive
- Leetcode:First Missing Positive
- 从输入url到显示网页,后台发生了什么?
- 学会根据错误追查问题,解决问题
- 2.多个非常有用的Java程序片段-常用java示例-常用示例-范例-公共方法-公用方法-2
- eclipse中配置maven
- ant external lib
- 【leetcode】First Missing Positive
- 用Python和Pygame写游戏-从入门到精通(3)
- Outlier Detection with DPM Slides from JSM 2011
- Linux环境下安装Nginx+Pcre+OpenSSL
- 学习型红外遥控的实现——stm32
- Android 安全机制概述 Permission
- 1069 Monkey and Banana
- 02-线性结构1. 一元多项式求导 (25)
- 基于BBB的4轮移动轮式机器人系统设计与实现(四)--BeagleBone Black PWM 应用程序开发