Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Mar 26, 2024
1 parent 79ea04f commit c7b0da5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions leetcode/41.FirstMissingPositive/sol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// https://leetcode.com/problems/first-missing-positive

package main

import "fmt"

func firstMissingPositive(nums []int) int {
m := make(map[int]bool)

for _, num := range nums {
if num > 0 {
m[num] = true
}
}

for i := 1; ; i++ {
if !m[i] {
return i
}
}
}

func main() {
nums := []int{3, 4, -1, 1}

fmt.Println(firstMissingPositive(nums))
}

0 comments on commit c7b0da5

Please sign in to comment.