From 7d79671d46914bec0f99c4d3fc81365ac4a10816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C5=9F=C4=B1nsu=20Ar=C4=B1c=C4=B1?= Date: Tue, 8 Mar 2022 21:41:06 +0300 Subject: [PATCH] 41 --- H_41_FirstMissingPositive.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 H_41_FirstMissingPositive.py diff --git a/H_41_FirstMissingPositive.py b/H_41_FirstMissingPositive.py new file mode 100644 index 0000000..3caac64 --- /dev/null +++ b/H_41_FirstMissingPositive.py @@ -0,0 +1,13 @@ +class Solution: + def firstMissingPositive(self, nums: List[int]) -> int: + n = len(nums) + nums.sort() + if(nums[0]>1 or nums[n-1]<0): + return 1 + for i in range(n-1): + if (nums[i+1]>1) and (nums[i]<0): + return 1 + if nums[i+1]-abs(nums[i])>1: + return nums[i]+1 + return nums[n-1]+1 + \ No newline at end of file