71. Simplify Path Medium

@problem@discussion
#String#Stack



1/**
2 * [71] Simplify Path
3 *
4 * Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path.
5 * In a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e. '//') are treated as a single slash '/'. For this problem, any other format of periods such as '...' are treated as file/directory names.
6 * The canonical path should have the following format:
7 * 
8 * 	The path starts with a single slash '/'.
9 * 	Any two directories are separated by a single slash '/'.
10 * 	The path does not end with a trailing '/'.
11 * 	The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period '.' or double period '..')
12 * 
13 * Return the simplified canonical path.
14 *  
15 * Example 1:
16 * 
17 * Input: path = "/home/"
18 * Output: "/home"
19 * Explanation: Note that there is no trailing slash after the last directory name.
20 * 
21 * Example 2:
22 * 
23 * Input: path = "/../"
24 * Output: "/"
25 * Explanation: Going one level up from the root directory is a no-op, as the root level is the highest level you can go.
26 * 
27 * Example 3:
28 * 
29 * Input: path = "/home//foo/"
30 * Output: "/home/foo"
31 * Explanation: In the canonical path, multiple consecutive slashes are replaced by a single one.
32 * 
33 *  
34 * Constraints:
35 * 
36 * 	1 <= path.length <= 3000
37 * 	path consists of English letters, digits, period '.', slash '/' or '_'.
38 * 	path is a valid absolute Unix path.
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/simplify-path/
44// discuss: https://leetcode.com/problems/simplify-path/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn simplify_path(path: String) -> String {
50        String::new()
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_71() {
62    }
63}
64


Back
© 2025 bowen.ge All Rights Reserved.