1496. Path Crossing Easy

@problem@discussion
#Hash Table#String



1/**
2 * [1496] Path Crossing
3 *
4 * Given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path.
5 * Return true if the path crosses itself at any point, that is, if at any time you are on a location you have previously visited. Return false otherwise.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/06/10/screen-shot-2020-06-10-at-123929-pm.png" style="width: 400px; height: 358px;" />
9 * Input: path = "NES"
10 * Output: false 
11 * Explanation: Notice that the path doesn't cross any point more than once.
12 * 
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2020/06/10/screen-shot-2020-06-10-at-123843-pm.png" style="width: 400px; height: 339px;" />
15 * Input: path = "NESWW"
16 * Output: true
17 * Explanation: Notice that the path visits the origin twice.
18 *  
19 * Constraints:
20 * 
21 * 	1 <= path.length <= 10^4
22 * 	path[i] is either 'N', 'S', 'E', or 'W'.
23 * 
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/path-crossing/
28// discuss: https://leetcode.com/problems/path-crossing/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33    pub fn is_path_crossing(path: String) -> bool {
34        false
35    }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_1496() {
46    }
47}
48


Back
© 2025 bowen.ge All Rights Reserved.