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简单应用的更多相关文章

  1. [LeetCode] First Missing Positive 首个缺失的正数

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  2. Leetcode First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  3. LeetCode: First Missing Positive 解题报告

    First Missing Positive Given an unsorted integer array, find the first missing positive integer. For ...

  4. LeetCode – First Missing Positive

    Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2, ...

  5. LeetCode OJ-- First Missing Positive

    https://oj.leetcode.com/problems/first-missing-positive/ 给一列数,找出缺失的第一个正数.要求时间复杂度 O(n) 第一步遍历一遍,找出最大的数 ...

  6. leetcode First Missing Positive python

    class Solution(object): def firstMissingPositive(self, nums): """ :type nums: List[in ...

  7. leetcode:First Missing Positive分析和实现

    题目大意: 传入整数数组nums,求nums中未出现的正整数中的最小值.要求算法在O(n)时间复杂度内实现,并且只能分配常量空间. 分析: 一般碰到这种问题,都先对数组进行排序,再遍历数组就可以找到最 ...

  8. [LeetCode] 41. First Missing Positive 首个缺失的正数

    Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2, ...

  9. leetcode 41 First Missing Positive ---java

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

随机推荐

  1. <script runat=server>、<%%>和<%#%>的区别

    ①<script runat="server">代码段与<%%>内联代码段的区别 在asp.net页面的aspx文件中允许使用<script runa ...

  2. c#中用DirectShow实现媒体播放器的核心(1) DirectShow简介

    用.net做多媒体开发的似乎不多,所以网上资源也少,看的人更少.不过我的博客上居然还有几位在等新文章的人,有点出乎我的意料了.目前我已不再从事多媒体相关的工作,加入新公司至今都忙到吐血,再加上害怕水平 ...

  3. LINQ 101——分区、Join、聚合

    一.Partitioning 分区 Take 例1:取前3个数 static void Linq1() { , , , , , , , , , }; ); Console.WriteLine(&quo ...

  4. JavaScript 快速入门回顾

    数据类型Number JavaScript不区分整数和浮点数,统一用Number表示,以下都是合法的Number类型: 123; // 整数123 0.456; // 浮点数0.456 1.2345e ...

  5. java设计模式和设计原则

    一.创建型模式 1.抽象工厂模式(Abstract factory pattern): 提供一个接口, 用于创建相关或依赖对象的家族, 而不需要指定具体类.2.生成器模式(Builder patter ...

  6. jQuery慢慢啃之工具(十)

    1.jQuery.support//一组用于展示不同浏览器各自特性和bug的属性集合 2.jQuery.browser//浏览器内核标识.依据 navigator.userAgent 判断. 可用值: ...

  7. linux安装git方法(转)

    转自:http://jingyan.baidu.com/article/e9fb46e16698687521f766ec.html 以下内容亲测,确实可行. 由于我的机器是linux6.7,所以省略了 ...

  8. markdown2 在win10下无法预览解决方案

    今天升级完Win10发现心爱的markdownPad 2无法预览,显示the view has crashed! 按照官网的Q&A http://markdownpad.com/faq.htm ...

  9. angularJS的controller之间如何正确的通信

    AngularJS中的controller是个函数,用来向视图的作用域($scope)添加额外的功能,我们用它来给作用域对象设置初始状态,并添加自定义行为. 当我们在创建新的控制器时,angularJ ...

  10. oracle系列索引

    今天终于把oracle入门的知识通篇过了一遍. 一篇文章没有写,先做个索引.把知识系统的梳理下. 数据库基本概念-oracle介绍 oracle安装,配置,启动 oracle工具 sqlplus 用户 ...