파비의 매일매일 공부기록

2023.04.12 Today's Challenge 본문

Problem Solving/LeetCode

2023.04.12 Today's Challenge

fabichoi 2023. 4. 12. 23:45

https://leetcode.com/problems/simplify-path/

 

Simplify Path - LeetCode

Can you solve this real interview question? Simplify Path - Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path. In a Unix-style file sys

leetcode.com

3일째 스택 관련 문제!

class Solution:
    def simplifyPath(self, path: str) -> str:
        st = []
        path = path.split('/')
        for p in path:
            if st and p == '..':
                st.pop()
            elif p not in ['.', '', '..']:
                st.append(p)
        return '/' + '/'.join(st)
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.04.14 Today's Challenge  (0) 2023.04.14
2023.04.13 Today's Challenge  (0) 2023.04.13
2023.04.11 Today's Challenge  (0) 2023.04.11
2023.04.10 Today's Challenge  (0) 2023.04.10
2023.04.09 Today's Challenge  (0) 2023.04.09
Comments