-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckStrainghtLine.java
More file actions
31 lines (30 loc) · 973 Bytes
/
CheckStrainghtLine.java
File metadata and controls
31 lines (30 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Leetcode - 1232
import java.util.*;
public class CheckStrainghtLine {
public static boolean isStraightLine(int[][] coordinates) {
int x1 = coordinates[0][0];
int y1 = coordinates[0][1];
int x2 = coordinates[1][0];
int y2 = coordinates[1][1];
for (int i = 2; i < coordinates.length; i++) {
int x3 = coordinates[i][0];
int y3 = coordinates[i][1];
if ((y2-y1)*(x3-x2) != (y3-y2)*(x2-x1)) {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] coordinates = new int[n][2];
for (int i = 0; i < coordinates.length; i++) {
for (int j = 0; j < 2; j++) {
coordinates[i][j] = sc.nextInt();
}
}
System.out.println(isStraightLine(coordinates));
sc.close();
}
}