MCPcopy Create free account
hub / github.com/EndlessCheng/codeforces-go / intersectionSizeTwo

Function intersectionSizeTwo

leetcode/main.go:1501–1516  ·  view source on GitHub ↗

LC 757

(a [][]int)

Source from the content-addressed store, hash-verified

1499
1500// LC 757
1501func intersectionSizeTwo(a [][]int) int {
1502 sort.Slice(a, func(i, j int) bool { a, b := a[i], a[j]; return a[1] < b[1] || a[1] == b[1] && a[0] > b[0] })
1503 ans := 2
1504 l, r := a[0][1]-1, a[0][1]
1505 for i := 1; i < len(a); i++ {
1506 ll, rr := a[i][0], a[i][1]
1507 if l < ll && ll <= r {
1508 ans++
1509 l, r = r, rr
1510 } else if r < ll {
1511 ans += 2
1512 l, r = rr-1, rr
1513 }
1514 }
1515 return ans
1516}
1517
1518// LC 803 打砖块
1519func hitBricks(g [][]int, hits [][]int) []int {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected