← 返回 meta 的题目列表Design Linux Command 'cd'
类型:online_judge
meta
Design a simple Linux 'cd' command to simulate Unix directory navigation. Implement the function change_directory(current_path: str, path: str) -> str. Parameters:
current_path is the current directory location.
path is the user input path which could be '../', '', or a subdirectory name. Return the resulting directory path after executing 'cd'.
Assumptions:
The path always begins at the root directory '/'. If it's an absolute path, it starts with '/'; otherwise, treat it as relative.
Use '/' to separate hierarchical directory levels.
Examples:
change_directory('/', 'home') returns '/home'
change_directory('/home', '../') returns '/'
change_directory('/home', 'user/files') returns '/home/user/files'
Example
Input
/
home