8000 :sparkles: Added solution to 1232 · ninefive/awesome-golang-leetcode@b90654b · GitHub
[go: up one dir, main page]

Skip to content

Commit b90654b

Browse files
author
Sathish Babu
committed
✨ Added solution to 1232
1 parent 6a12c94 commit b90654b

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/1232.Check-If-It-Is-a-Straight-Line/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
66
## Description
77

8+
You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.
9+
10+
**Example 1:**
11+
12+
```
13+
Input: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
14+
Output: true
15+
```
16+
817
**Example 1:**
918

1019
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
20+
Input: coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]
21+
Output: false
1322
```
1423

1524
## 题意
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(coordinates [][]int) bool {
4+
dx0 := coordinates[1][0] - coordinates[0][0]
5+
dy0 := coordinates[1][1] - coordinates[0][1]
6+
for i := 1; i < len(coordinates)-1; i++ {
7+
dx := coordinates[i+1][0] - coordinates[i][0]
8+
dy := coordinates[i+1][1] - coordinates[i][1]
9+
if dy*dx0 != dy0*dx {
10+
return false
11+
}
12+
}
13+
return true
514
}

src/1232.Check-If-It-Is-a-Straight-Line/Solution_test.go

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

2120
// 开始测试

0 commit comments

Comments
 (0)
0