First Missing Positive LeetCode上的41题:https://leetcode-cn.com/problems/first-missing-positive/description/ First Missing Positive 题目题解代码 题目 Given an unsorted integer array, find the small
这道题写的时候完全没有思路,看了很久的题解,才总结出来。 class Solution:def firstMissingPositive(self, nums: List[int]) -> int:nums_set = set(nums)n = len(nums)for i in range(1, n + 1):if i not in nums_set:return ireturn n + 1
文章目录 一、题目二、题解 一、题目 Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.
Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant sp