← 返回 meta 的题目列表Simplify Absolute Unix File Path with Current Directory
类型:online_judge
meta
Given an absolute Unix file path and a current working directory cwd, return the simplified path after removing redundant .s, ..s, and //. Examples:
Input: path = "/home/", cwd = "/usr", Output: "/home"
Input: path = "/a/./b/../../c/", cwd = "/usr/local", Output: "/c"
Input: path = "/../", cwd = "/usr/local", Output: "/"
Requirements:
Time complexity: O(n), where n is the length of the path.
Input Description:
A string path representing the Unix file path to simplify.
A string cwd representing the current working directory.
Output Description:
Return the simplified path without redundant components.
Note: The input path is always an absolute path and does not begin with ~.
Example
Input
/home/\n/usr