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] ...
随机推荐
- PL/SQL 访问网页(get or post方式)
在我们开发plsql程序的过程中,有时候难免要访问一些外部网站的数据.这个时候我们就要用到utl_http包. 使用utl_http包前需要注意的是,当前的用户下是否有访问外部网络的权限. 如下是自己 ...
- JavaWeb学习----JSP简介及入门(JSP结构及JSP处理)
[声明] 欢迎转载,但请保留文章原始出处→_→ 艾水及水:http://www.cnblogs.com/liuhepeng 文章来源:http://www.cnblogs.com/liuhepeng ...
- hdu 1396 Counting Triangles(递推)
Counting Triangles Problem Description Given an equilateral triangle with n thelength of its side, p ...
- js 中对象属性的特性
数据属性: 数据属性包含一个数据值的位置,在这个位置可以读取和写入值. 4个描述的行为特性: writable 表示能否修改属性的值.默认为true Enumerable 表示能否过过for in循 ...
- Django 基础
Django 的路由系统 在 django 的 URLconf 配置文件 urls.py 中根据一个 URL 对应 views 的一个函数来处理用户的请求. 1.基本的 urls 对应 urlpatt ...
- WPF内嵌代码和后台代码简单混合使用
下面实例展示了WPF内嵌代码和后台代码混合使用,一个简单基础的实例: xaml文件: <Window x:Class="WPF内嵌代码和后台代码混合使用.MainWindow" ...
- string与char* 互相转换以及周边问题
先插一个小知识点 string str = "abc" str += 'd'; cout<<str<<endl; //"abcd" ...
- C语言的预处理命令
C语言编译器处理时经过的第一个步骤是预处理,就是从.c文件处理为.i文件.在预处理时编译器做了一些展开替换的处理. 1>头文件展开,即将#include "stdio.h"类 ...
- 【算法】一般冒泡排序 O(n^2) 稳定的 C语言
冒泡排序 一.算法描述 假设序列中有N个元素: 第一趟选取第一个元素作为关键字,从左至右比较,若遇到比它小的则放到它左边(也即两数进行交换),若遇到比它大的,则改为选取该元素作为关键字完成后续的比较, ...
- bzoj 1053: [HAOI2007]反素数ant 搜索
1053: [HAOI2007]反素数ant Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1497 Solved: 821[Submit][Sta ...