Skip to content

Commit

Permalink
Create 41. First missing positive
Browse files Browse the repository at this point in the history
  • Loading branch information
dishathakurata authored Mar 26, 2024
1 parent e48fef9 commit b8b14e2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 41. First missing positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//41. First missing positive

class Solution {
public int firstMissingPositive(int[] nums) {
int n = nums.length;
boolean[] found = new boolean[n + 1];

for(int i = 0; i < n; i++) {
if(nums[i] > 0 && nums[i] <= n) {
found[nums[i]] = true;
}
}

for(int i= 1; i <=n; i++) {
if(!found[i]) {
return i;
}
}

return n+1;
}
}

0 comments on commit b8b14e2

Please sign in to comment.