Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 78e2a0b

Browse files
aQuaaQua
aQua
authored and
aQua
committed
836 finish
1 parent 0e992ef commit 78e2a0b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
package problem0836
22

33
func isRectangleOverlap(rec1 []int, rec2 []int) bool {
4-
5-
return false
4+
// 把 rec 分别投影到水平轴和竖直轴上
5+
h1, v1 := projecting(rec1)
6+
h2, v2 := projecting(rec2)
7+
// 两个投影线同时相交可以认为 rec 相交
8+
return isLineOverlap(h1, h2) && isLineOverlap(v1, v2)
9+
}
10+
11+
func projecting(rec []int) (h, v []int) {
12+
h = []int{rec[0], rec[2]}
13+
v = []int{rec[1], rec[3]}
14+
return
15+
}
16+
17+
func isLineOverlap(a, b []int) bool {
18+
// 没有分开,就是相交
19+
return !(a[1] <= b[0] || b[1] <= a[0])
620
}

0 commit comments

Comments
 (0)