-
Notifications
You must be signed in to change notification settings - Fork 111
/
self-crossing.cc
26 lines (26 loc) · 986 Bytes
/
self-crossing.cc
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
// Self Crossing
/* https://leetcode.com/discuss/88153/another-python
b b
+----------------+ +----------------+
| | | |
| | | | a
c | | c | |
| | a | | f
+-----------> | | | <----+
d | | | | e
| | |
+-----------------------+
d
*/
class Solution {
public:
bool isSelfCrossing(vector<int>& x) {
int a = 0, b = 0, c = 0, d = 0, e = 0;
for (int f: x) {
if (c && d <= f && e <= c || b && b <= d && d <= b+f && e <= c && c <= a+e)
return true;
a = b, b = c, c = d, d = e, e = f;
}
return false;
}
};