Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb90654b

Browse files
author
Sathish Babu
committed
✨ Added solution to 1232
1 parent6a12c94 commitb90654b

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-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(coordinates [][]int)bool {
4+
dx0:=coordinates[1][0]-coordinates[0][0]
5+
dy0:=coordinates[1][1]-coordinates[0][1]
6+
fori:=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+
ifdy*dx0!=dy0*dx {
10+
returnfalse
11+
}
12+
}
13+
returntrue
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
namestring
13-
inputsbool
13+
inputs[][]int
1414
expectbool
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}},false},
1918
}
2019

2120
//开始测试

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp