leetcode First Missing Positive hashset简单应用
public class Solution {
public int firstMissingPositive(int[] A) {
HashSet<Integer> hash=new HashSet<Integer>();
int count=0;
int sum=0;
for(int i:A)
{
if(i>0)
{
hash.add(i);
}
}
int beg=1;
while(hash.contains(beg))
{
beg++;
}
return beg;
}
}
V
public class Solution {
public int firstMissingPositive(int[] A) {
HashSet<Integer> hash=new HashSet<Integer>();
int count=0;
int sum=0;
for(int i:A)
{
if(i>0)
{
hash.add(i);
}
}
int beg=1;
while(hash.contains(beg))
{
beg++;
}
return beg;
}
}
w Code
leetcode First Missing Positive hashset简单应用的更多相关文章
- [LeetCode] First Missing Positive 首个缺失的正数
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
- Leetcode First Missing Positive
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
- LeetCode: First Missing Positive 解题报告
First Missing Positive Given an unsorted integer array, find the first missing positive integer. For ...
- LeetCode – First Missing Positive
Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2, ...
- LeetCode OJ-- First Missing Positive
https://oj.leetcode.com/problems/first-missing-positive/ 给一列数,找出缺失的第一个正数.要求时间复杂度 O(n) 第一步遍历一遍,找出最大的数 ...
- leetcode First Missing Positive python
class Solution(object): def firstMissingPositive(self, nums): """ :type nums: List[in ...
- leetcode:First Missing Positive分析和实现
题目大意: 传入整数数组nums,求nums中未出现的正整数中的最小值.要求算法在O(n)时间复杂度内实现,并且只能分配常量空间. 分析: 一般碰到这种问题,都先对数组进行排序,再遍历数组就可以找到最 ...
- [LeetCode] 41. First Missing Positive 首个缺失的正数
Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2, ...
- leetcode 41 First Missing Positive ---java
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
随机推荐
- 7z 压缩命令行工具
命令行压缩解压一 7z 1) 简介7z,全称7-Zip, 是一款开源软件.是目前公认的压缩比例最大的压缩解压软件.主页:http://www.7-zip.org/中文主页:http://7z.spar ...
- struts -执行流程
When a client request is given, a web container will receive request Web container loads web.xml and ...
- pat_1008
1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...
- 使用微软企业库5.0提供的unity配置解藕系统demo(源码)
最近公司集50多号开发人员的人力围绕一个系统做开发,框架是免不了要统一的,公司提供的架构,利于分工合作,便于维护,扩展,升级,其中使用了到微软的企业库来解藕系统,只是因为框架封装,于是在网上学习了一个 ...
- CoreAnimation1-图层树、寄宿图以及图层几何学
(一)图层的树状结构 Core Animation其实是一个令人误解的命名.你可能认为它只是用来做动画的,但实际上它是从一个叫做Layer Kit这么一个不怎么和动画有关的名字演变而来,所以做动画这只 ...
- 【AngularJS】——0.分析
[引导分析]1.什么是AngularJS? 2.为什么要使用它? 3.应用场合? 4.基本思想? 5.四大核心特征? 6.优缺点是什么? 1.定义:AngularJS是一个用于设计动态web应用的前端 ...
- Gulp那些好用的插件 2016.04.20
开始接触LESS.组件化编程后,慢慢意识到需要一个提高工作效率的构建工具,就此接触到了Gulp. Gulp的好处在这里就不细说啦,只有四个API接口学起来简直爽歪歪,减少了大量的I/O操作,用起来很畅 ...
- 对有状态bean和无状态bean的理解(转)
现实中,很多朋友对两种session bean存在误解,认为有状态是实例一直存在,保存每次调用后的状态,并对下一次调用起作用,而认为无状态是每次调用实例化一次,不保留用户信息.仔细分析并用实践检验后, ...
- Java虚拟机类加载初始化解析
Classloader的作用,概括来说就是将编译后的class装载.加载到机器内存中,为了以后的程序的执行提供前提条件. 一段程序引发的思考: 风中叶老师在他的视频中给了我们一段程序,号称是世界上所有 ...
- localStorage.ie6.js
!window.localStorage && function() { window.localStorage = {}; var prefix = 'data-userdata' ...