455.assign-cookies.go 203 B

12345678910111213
  1. func findContentChildren(g []int, s []int) int {
  2. sort.Ints(g)
  3. sort.Ints(s)
  4. cnt := 0
  5. for i, j := len(g)-1, len(s)-1; 0 <= i && 0 <= j; {
  6. if g[i] <= s[j] {
  7. j--
  8. cnt++
  9. }
  10. i--
  11. }
  12. return cnt
  13. }