forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
33 lines (25 loc) · 743 Bytes
/
main.cpp
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
31
32
33
/// Source : https://leetcode.com/problems/check-if-it-is-a-straight-line/
/// Author : liuyubobobo
/// Time : 2019-10-19
#include <iostream>
#include <vector>
using namespace std;
/// Linear Scan
/// Time Complexity: O(n)
/// Space Complexity: O(1)
class Solution {
public:
bool checkStraightLine(vector<vector<int>>& coordinates) {
int a = coordinates[1][1] - coordinates[0][1];
int b = coordinates[1][0] - coordinates[0][0];
for(int i = 2; i < coordinates.size(); i ++){
int y = coordinates[i][1] - coordinates[0][1];
int x = coordinates[i][0] - coordinates[0][0];
if(y * b != x * a) return false;
}
return true;
}
};
int main() {
return 0;
}