Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Jan 15, 2024
1 parent cba49a6 commit 27ce95f
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// https://leetcode.com/problems/find-players-with-zero-or-one-losses/

package main

import (
"fmt"
"sort"
)

func findWinners(matches [][]int) [][]int {
cnt := map[int]int{}
for _, m := range matches {
a, b := m[0], m[1]
if _, ok := cnt[a]; !ok {
cnt[a] = 0
}
cnt[b]++
}
result := make([][]int, 2)
for u, v := range cnt {
if v < 2 {
result[v] = append(result[v], u)
}
}
sort.Ints(result[0])
sort.Ints(result[1])
return result
}

func main() {
matches := [][]int{{1, 3}, {2, 3}, {3, 6}, {5, 6}, {5, 7}, {4, 5}, {4, 8}, {4, 9}, {10, 4}, {10, 9}}

fmt.Println(findWinners(matches))
}

0 comments on commit 27ce95f

Please sign in to comment.