You are given an absolute path for a Unix-style file system, which always begins with a slash '/'
. Your task is to transform this absolute path into its simplified canonical path.
The rules of a Unix-style file system are as follows:
'.'
represents the current directory.'..'
represents the previous/parent directory.'//'
and '///'
are treated as a single slash '/'
.'...'
and '....'
are valid directory or file names.The simplified canonical path should follow these rules:
'/'
.'/'
.'/'
, unless it is the root directory.'.'
and '..'
) used to denote current or parent directories.Return the simplified canonical path.
Example 1:
Input: path = "/home/"
Output: "/home"
Explanation:
The trailing slash should be removed.
Example 2: