335. Self Crossing Hard
1/**
2 * [335] Self Crossing
3 *
4 * You are given an array of integers distance.
5 * You start at point (0,0) on an X-Y plane and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[3] meters to the east, and so on. In other words, after each move, your direction changes counter-clockwise.
6 * Return true if your path crosses itself, and false if it does not.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/14/selfcross1-plane.jpg" style="width: 400px; height: 435px;" />
10 * Input: distance = [2,1,1,2]
11 * Output: true
12 *
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/14/selfcross2-plane.jpg" style="width: 400px; height: 435px;" />
15 * Input: distance = [1,2,3,4]
16 * Output: false
17 *
18 * Example 3:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/14/selfcross3-plane.jpg" style="width: 400px; height: 435px;" />
20 * Input: distance = [1,1,1,1]
21 * Output: true
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= distance.length <= 10^5
27 * 1 <= distance[i] <= 10^5
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/self-crossing/
33// discuss: https://leetcode.com/problems/self-crossing/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn is_self_crossing(distance: Vec<i32>) -> bool {
39 false
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_335() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.