로딩
요청 처리 중입니다...

JAVA_LeetCode 71_Simplify Path

 JAVA_LeetCode 71_Simplify Path

JAVA_LeetCode 71_Simplify Path 풀이 class Solution { public String simplifyPath(String path) { // 스택을 이용한 풀이법 Stack stack = new Stack(); String[] arr = path.split("/"); for(String str : arr){ if(str.equals(".") || str.isEmpty()) continue; // . 또는 비어있을경우 무시 else if(str.equals("..")){ // 상위 디렉토리인경우 if(!

stack.isEmpty()) stack.pop(); // 있을 때 빼기 }else stack.push(str); // 나머지인경우 추가 } return "/" + String.join("/", stack); // 루트와 스택 합치기 } } 스택, 실제 사용되는 디렉토리 경로 표시로 추정 * 출처 https://leetcode.com/pr...