Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param {number[]} nums
- * @return {number}
- */
- var firstMissingPositive = function(nums) {
- if (!nums.length) {
- return 1;
- }
- var additionalStorage = new Array(nums.length);
- nums.forEach((num) => {
- if (num <= nums.length && num > 0) {
- additionalStorage[num - 1] = true;
- }
- });
- for (var i = 0; i < additionalStorage.length; ++i) {
- if (!additionalStorage[i]) {
- return i + 1;
- }
- }
- return nums.length + 1;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement