@@ -0,0 +1,1786 @@
+/***%0A * Given an absolute path for a file (Unix-style), simplify it.%0A *%0A * For example,%0A * path = %22/home/%22, =%3E %22/home%22%0A * path = %22/a/./b/../../c/%22, =%3E %22/c%22%0A * click to show corner cases.%0A *%0A * Corner Cases:%0A * Did you consider the case where path = %22/../%22?%0A * In this case, you should return %22/%22.%0A * Another corner case is the path might contain multiple slashes '/' together, such as %22/home//foo/%22.%0A * In this case, you should ignore redundant slashes and return %22/home/foo%22.%0A */%0Aimport java.util.ArrayList;%0Apublic class SimplifyPath %7B%0A    public String simplifyPath(String path) %7B%0A        ArrayList%3CString%3E stk = new ArrayList%3CString%3E();%0A        String dir;%0A        int j;%0A        for (int i = 0; i %3C path.length(); i++) %7B%0A            j = path.indexOf('/', i);%0A            if (j == -1) %7B%0A                j = path.length();%0A                dir = path.substring(i, j);%0A            %7D else if( j == i) %7B%0A                dir = new String();%0A            %7D else %0A                dir = path.substring(i, j);%0A            if (dir.length() != 0 && !dir.equals(%22.%22)) %7B%0A                System.out.printf(%22dir %25s%5Cn%22, dir);%0A                if (dir.equals(%22..%22))%7B%0A                    if (stk.size() %3E 0)%0A                        stk.remove(stk.size() - 1);%0A                %7D else %0A                    stk.add(dir);%0A            %7D%0A            i = j;%0A        %7D%0A        if (stk.size() == 0)    %0A            return %22/%22;%0A        StringBuffer sb = new StringBuffer();%0A        for (String s: stk) %7B%0A            sb.append('/');%0A            sb.append(s);%0A        %7D%0A        return sb.toString();%0A    %7D%0A%0A    public static void main (String args%5B%5D) %7B%0A        SimplifyPath sp = new SimplifyPath();%0A        String s = sp.simplifyPath(%22/...%22);%0A        System.out.printf(%22Simplified path of /... is %25s%5Cn%22, s);%0A    %7D%0A%7D%0A

add SimplifyPath.java