71. Simplify Path 发表于 2022-05-22 123456789101112131415161718192021222324252627282930class Solution { public String simplifyPath(String path) { Deque<String> deque = new LinkedList<>(); for (String str : path.split("/")) { switch (str) { case ".": case "": // ignore break; case "..": if (!deque.isEmpty()) { deque.removeLast(); } break; default: deque.addLast(str); } } if (deque.isEmpty()) { return "/"; } else { StringBuilder sb = new StringBuilder(); for (String str : deque) { sb.append("/").append(str); } return sb.toString(); } }} Reference71. Simplify Path