
g0001_0100.s0041_first_missing_positive.Solution.cpp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
The newest version!
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Udemy_Arrays
// #Big_O_Time_O(n)_Space_O(n) #2024_05_24_Time_42_ms_(69.19%)_Space_53.4_MB_(25.71%)
class Solution {
public:
int firstMissingPositive(vector& nums) {
int n=nums.size();
for (int i=0;i 0) {
nums[abs(nums[i])-1] *= -1;
}
}
for (int i=0;i 0) {
return i+1;
}
}
return n+1;
}
};
© 2015 - 2025 Weber Informatics LLC | Privacy Policy