forked from keineahnung2345/leetcode-cpp-practices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1037. Valid Boomerang.cpp
28 lines (25 loc) · 938 Bytes
/
1037. Valid Boomerang.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
//Runtime: 0 ms, faster than 100.00% of C++ online submissions for Valid Boomerang.
//Memory Usage: 7.4 MB, less than 100.00% of C++ online submissions for Valid Boomerang.
class Solution {
public:
bool isBoomerang(vector<vector<int>>& points) {
//same point?
vector<int> a = points[0], b = points[1], c = points[2];
if((a[0] == b[0] && a[1] == b[1]) || (a[0] == c[0] && a[1] == c[1]) || (b[0] == c[0] && b[1] == c[1]))
return false;
//on same vertical line?
if(a[0] == b[0] || a[0] == c[0]){
if((a[0] == b[0]) && (a[0] == c[0])){
return false;
}
return true;
}
//same slope?
double slope = (a[1] - b[1])/(double)(a[0] - b[0]);
if(a[0] == c[0]) return false;
if((a[1]-c[1])/(double)(a[0]-c[0]) == slope){
return false;
}
return true;
}
};