|
15 | 15 |
|
16 | 16 | <p>Write a one-pass algorithm with <code>O(1)</code> extra space to determine, if your path crosses itself, or not.</p>
|
17 | 17 |
|
| 18 | +<p> </p> |
| 19 | + |
18 | 20 | <p><b>Example 1:</b></p>
|
19 | 21 |
|
20 | 22 | <pre>
|
21 | | -<strong>Input: </strong><code>[2,1,1,2]</code> |
22 | | - |
23 | | -????? |
24 | | -? ? |
25 | | -???????> |
26 | | - ? |
| 23 | +<strong>┌───┐ |
| 24 | +│ │ |
| 25 | +└───┼──> |
| 26 | + │ |
27 | 27 |
|
28 | | -<strong>Input: </strong>true |
29 | | -<strong>Explanation:</strong> self crossing |
| 28 | +Input: </strong><code>[2,1,1,2]</code> |
| 29 | +<strong>Output: </strong>true |
30 | 30 | </pre>
|
31 | 31 |
|
32 | 32 | <p><b>Example 2:</b></p>
|
33 | 33 |
|
34 | 34 | <pre>
|
35 | | -<strong>Input:</strong> <code>[1,2,3,4]</code> |
36 | | - |
37 | | -???????? |
38 | | -? ? |
39 | | -? |
40 | | -? |
41 | | -?????????????> |
| 35 | +<strong>┌──────┐ |
| 36 | +│ │ |
| 37 | +│ |
| 38 | +│ |
| 39 | +└────────────> |
42 | 40 |
|
| 41 | +Input:</strong> <code>[1,2,3,4]</code> |
43 | 42 | <strong>Output: </strong>false
|
44 | | -<strong>Explanation: </strong>not self crossing |
45 | 43 | </pre>
|
46 | 44 |
|
47 | 45 | <p><b>Example 3:</b></p>
|
48 | 46 |
|
49 | 47 | <pre>
|
50 | | -<strong>Input:</strong> <code>[1,1,1,1]</code> |
51 | | - |
52 | | -????? |
53 | | -? ? |
54 | | -?????> |
| 48 | +<strong>┌───┐ |
| 49 | +│ │ |
| 50 | +└───┼> |
55 | 51 |
|
| 52 | +Input:</strong> <code>[1,1,1,1]</code> |
56 | 53 | <strong>Output:</strong> true
|
57 | | -<strong>Explanation:</strong> self crossing |
58 | 54 | </pre>
|
59 | 55 |
|
60 | 56 | ### Related Topics
|
|
0 commit comments