规范格式

This commit is contained in:
YDZ
2020-08-07 15:50:06 +08:00
parent 854a339abc
commit 4e11f4028a
1438 changed files with 907 additions and 924 deletions

View File

@ -0,0 +1,5 @@
package leetcode
func isRectangleOverlap(rec1 []int, rec2 []int) bool {
return rec1[0] < rec2[2] && rec2[0] < rec1[2] && rec1[1] < rec2[3] && rec2[1] < rec1[3]
}

View File

@ -0,0 +1,48 @@
package leetcode
import (
"fmt"
"testing"
)
type question836 struct {
para836
ans836
}
// para 是参数
// one 代表第一个参数
type para836 struct {
rec1 []int
rec2 []int
}
// ans 是答案
// one 代表第一个答案
type ans836 struct {
one bool
}
func Test_Problem836(t *testing.T) {
qs := []question836{
question836{
para836{[]int{0, 0, 2, 2}, []int{1, 1, 3, 3}},
ans836{true},
},
question836{
para836{[]int{0, 0, 1, 1}, []int{1, 0, 2, 1}},
ans836{false},
},
}
fmt.Printf("------------------------Leetcode Problem 836------------------------\n")
for _, q := range qs {
_, p := q.ans836, q.para836
fmt.Printf("【input】:%v 【output】:%v\n", p, isRectangleOverlap(p.rec1, p.rec2))
}
fmt.Printf("\n\n\n")
}

View File

@ -0,0 +1,41 @@
# [836. Rectangle Overlap](https://leetcode.com/problems/rectangle-overlap/)
## 题目:
A rectangle is represented as a list `[x1, y1, x2, y2]`, where `(x1, y1)` are the coordinates of its bottom-left corner, and `(x2, y2)` are the coordinates of its top-right corner.
Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.
Given two (axis-aligned) rectangles, return whether they overlap.
**Example 1:**
Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3]
Output: true
**Example 2:**
Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1]
Output: false
**Notes:**
1. Both rectangles `rec1` and `rec2` are lists of 4 integers.
2. All coordinates in rectangles will be between `-10^9` and `10^9`.
## 题目大意
矩形以列表 [x1, y1, x2, y2] 的形式表示,其中 (x1, y1) 为左下角的坐标,(x2, y2) 是右上角的坐标。如果相交的面积为正,则称两矩形重叠。需要明确的是,只在角或边接触的两个矩形不构成重叠。给出两个矩形,判断它们是否重叠并返回结果。
说明:
1. 两个矩形 rec1 和 rec2 都以含有四个整数的列表的形式给出。
2. 矩形中的所有坐标都处于 -10^9 和 10^9 之间。
## 解题思路
- 给出两个矩形的坐标,判断两个矩形是否重叠。
- 几何题,按照几何方法判断即可。