diff --git a/algorithms/unix/path/simplify_path.py b/algorithms/unix/path/simplify_path.py index 8880fc0c6..7cdf4581e 100644 --- a/algorithms/unix/path/simplify_path.py +++ b/algorithms/unix/path/simplify_path.py @@ -14,10 +14,12 @@ Reference: https://leetcode.com/problems/simplify-path/description/ """ +import posixpath + -import os def simplify_path_v1(path): - return os.path.abspath(path) + return posixpath.normpath(path) + def simplify_path_v2(path): stack, tokens = [], path.split("/") diff --git a/tests/test_unix.py b/tests/test_unix.py index 3cafba98f..63bf4cffc 100644 --- a/tests/test_unix.py +++ b/tests/test_unix.py @@ -22,11 +22,11 @@ def test_join_with_slash(self): def test_full_path(self): file_name = "file_name" # Test full path relative - expect_path = "{}/{}".format(os.getcwd(), file_name) + expect_path = os.path.join('{}', '{}').format(os.getcwd(), file_name) self.assertEqual(expect_path, full_path(file_name)) # Test full path with expanding user # ~/file_name - expect_path = "{}/{}".format(os.path.expanduser('~'), file_name) + expect_path = os.path.join('{}', '{}').format(os.path.expanduser('~'), file_name) self.assertEqual(expect_path, full_path("~/{}".format(file_name))) def test_split(self):