leetcode First Missing Positive python
class Solution(object):
def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
intlen=len(nums)
i=0
while i < intlen:
if nums[i] > 0 and nums[i] < intlen and nums[i] != nums[nums[i]-1]:
#get the current num, and put it into it's right place
#for example : if get the third item is 5 ( index is 2, start with 0 ) , so the index of 5 should be 4
tmp=nums[nums[i]-1]
nums[nums[i]-1]=nums[i]
nums[i]=tmp
else:
i+=1 for i in range(intlen):
if nums[i] != i+1:
return i+1 return intlen+1
leetcode First Missing Positive python的更多相关文章
- [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 hashset简单应用
public class Solution { public int firstMissingPositive(int[] A) { HashSet<Integer> hash=new H ...
- leetcode:First Missing Positive分析和实现
题目大意: 传入整数数组nums,求nums中未出现的正整数中的最小值.要求算法在O(n)时间复杂度内实现,并且只能分配常量空间. 分析: 一般碰到这种问题,都先对数组进行排序,再遍历数组就可以找到最 ...
- [LeetCode]题解(python):041-First Missing Positive
题目来源 https://leetcode.com/problems/first-missing-positive/ Given an unsorted integer array, find the ...
- [Leetcode][Python]41: First Missing Positive
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 41: First Missing Positivehttps://oj.le ...
随机推荐
- 固定表格行列(expression)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- SQL Common Sense 碎片一
1.关于时间 SELECT GETDATE() SELECT DATEPART(d,'2014-05-20 14:20:55.347') SELECT DATEDIFF(d,'2014-05-20 1 ...
- js 多媒体audio video
本文主要简单的介绍一下audio 和 video两个标签的用法 <audio src="music.mp3"></audio> <video src= ...
- HTTP Status 404 - No result defined for action com.hebky.oa.classEntity.action.EntitysAction and result input
在开发中总遇到这个问题,No result defined for action:原因:Action中的属性值为空的时候,Struts2的默认拦截器会报错,但是又找不到input的Result,不能够 ...
- CoreLocation导航Demo
CoreLocation实现定位和导航功能还是非常简单的,基本思路是: 1.导入<CoreLocation/CoreLocation.h>头文件 2.使用该框架内的导航管理者,创建该导航管 ...
- HDU 3030 - Increasing Speed Limits
Problem Description You were driving along a highway when you got caught by the road police for spee ...
- LeetCode之ReverseWorldString
题目:将一个英文句子翻转,比如:the sky is blue 翻转后变为:blue is sky the 分析:我的实现方法是,利用栈将单词存储起来,然后再顺序拿出来,单词进栈还需注意添加空格. 主 ...
- php变量的引用及函数的引用
Php变量的引用及函数的引用放回 变量的引用 $a="ABC"; $b =&$a; echo $a;//这里输出:ABC echo $b;//这里输 ...
- Android之修改部分字体颜色
#01# 方法一: TextView textView = (TextView) view.findViewById(R.id.text); SpannableString ss = new Span ...
- 稀疏图(邻接链表),并查集,最短路径(Dijkstra,spfa),最小生成树(kruskal,prim)
全部函数通过杭电 1142,1162,1198,1213等题目测试. #include<iostream> #include<vector> #include<queue ...