Skip to content

Commit 35ebe88

Browse files
committed
Add solution and test-cases for problem 3025
1 parent df4288a commit 35ebe88

File tree

6 files changed

+80
-22
lines changed

6 files changed

+80
-22
lines changed
29.2 KB
Loading
28.9 KB
Loading
23.9 KB
Loading

leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/README.md

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,60 @@
11
# [3025.Find the Number of Ways to Place People I][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
You are given a 2D array `points` of size `n x 2` representing integer coordinates of some points on a 2D plane, where `points[i] = [xi, yi]`.
5+
6+
Count the number of pairs of points `(A, B)`, where
7+
8+
- `A` is on the **upper left** side of `B`, and
9+
- there are no other points in the rectangle (or line) they make (**including the border**).
10+
11+
Return the count.
12+
13+
**Example 1:**
714

8-
**Example 1:**
15+
![1](./1.png)
916

1017
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
18+
Input: points = [[1,1],[2,2],[3,3]]
19+
20+
Output: 0
21+
22+
Explanation:
23+
24+
There is no way to choose A and B so A is on the upper left side of B.
1325
```
1426

15-
## 题意
16-
> ...
27+
**Example 2:**
1728

18-
## 题解
29+
![2](./2.jpg)
1930

20-
### 思路1
21-
> ...
22-
Find the Number of Ways to Place People I
23-
```go
2431
```
32+
Input: points = [[6,2],[4,4],[2,6]]
33+
34+
Output: 2
35+
36+
Explanation:
2537
38+
The left one is the pair (points[1], points[0]), where points[1] is on the upper left side of points[0] and the rectangle is empty.
39+
The middle one is the pair (points[2], points[1]), same as the left one it is a valid pair.
40+
The right one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0], but points[1] is inside the rectangle so it's not a valid pair.
41+
```
42+
43+
**Example 3:**
44+
45+
![3](./3.jpg)
46+
47+
```
48+
Input: points = [[3,1],[1,3],[1,1]]
49+
50+
Output: 2
51+
52+
Explanation:
53+
54+
The left one is the pair (points[2], points[0]), where points[2] is on the upper left side of points[0] and there are no other points on the line they form. Note that it is a valid state when the two points form a line.
55+
The middle one is the pair (points[1], points[2]), it is a valid pair same as the left one.
56+
The right one is the pair (points[1], points[0]), it is not a valid pair as points[2] is on the border of the rectangle.
57+
```
2658

2759
## 结语
2860

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(points [][]int) int {
4+
ans := 0
5+
l := len(points)
6+
for i := 0; i < l; i++ {
7+
for j := 0; j < l; j++ {
8+
// 检查他俩是否ok
9+
if i == j || !(points[i][0] <= points[j][0] && points[i][1] >= points[j][1]) {
10+
// 不在左上角
11+
continue
12+
}
13+
k := 0
14+
for ; k < l; k++ {
15+
if k == i || k == j {
16+
continue
17+
}
18+
x := points[k][0] <= points[j][0] && points[k][0] >= points[i][0]
19+
y := points[k][1] >= points[j][1] && points[k][1] <= points[i][1]
20+
if x && y {
21+
break
22+
}
23+
}
24+
if k == l {
25+
ans++
26+
}
27+
28+
}
29+
}
30+
return ans
531
}

leetcode/3001-3100/3025.Find-the-Number-of-Ways-to-Place-People-I/Solution_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs [][]int
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", [][]int{{1, 1}, {2, 2}, {3, 3}}, 0},
17+
{"TestCase2", [][]int{{6, 2}, {4, 4}, {2, 6}}, 2},
18+
{"TestCase3", [][]int{{3, 1}, {1, 3}, {1, 1}}, 2},
1919
}
2020

2121
// 开始测试
@@ -30,10 +30,10 @@ func TestSolution(t *testing.T) {
3030
}
3131
}
3232

33-
// 压力测试
33+
// 压力测试
3434
func BenchmarkSolution(b *testing.B) {
3535
}
3636

37-
// 使用案列
37+
// 使用案列
3838
func ExampleSolution() {
3939
}

0 commit comments

Comments
 (0)