@@ -0,0 +1,957 @@
+package problems;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class SimplifyPath %7B%0A    public String simplifyPath(String path) %7B%0A        if (path == null %7C%7C path.length() == 0)%0A            return %22%22;%0A%0A        String%5B%5D sa = path.split(%22/%22);%0A        List%3CString%3E list = new ArrayList%3CString%3E();%0A        for (String s : sa) %7B%0A            if (s.length() == 0 %7C%7C s.equals(%22.%22))%0A                continue;%0A            if (s.equals(%22..%22)) %7B%0A                if (list.size() %3E 0)%0A                    list.remove(list.size() - 1);%0A            %7D else%0A                list.add(s);%0A        %7D%0A%0A        if (list.size() == 0)%0A            return %22/%22;        %0A        String out = %22%22;%0A        for (String s : list) %7B%0A            out += %22/%22 + s;%0A        %7D%0A        return out;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        SimplifyPath sp = new SimplifyPath();%0A        String s = %22/abc/...%22;%0A        System.out.println(sp.simplifyPath(s));%0A    %7D%0A%7D%0A

Add Simplify Path