Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions algorithms/unix/path/simplify_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down