LeetCode – Simplify Path (Java)
Given an absolute path for a file (Unix-style), simplify it. For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c” path = “/../”, => “/” path = “/home//foo/”, => “/home/foo” Java Solution public String simplifyPath(String path) { Stack<String> stack = new Stack<String>(); //stack.push(path.substring(0,1)); while(path.length()> 0 && path.charAt(path.length()-1) ==’/’){ path = path.substring(0, … Read more