@@ -0,0 +1,1566 @@
+// 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%0A%0Apublic class Solution %7B%0A    public String simplifyPath(String path) %7B%0A        int len = path.length();%0A%0A        if(len == 0) return path;%0A%0A        List%3CString%3E list = new ArrayList%3CString%3E();%0A%0A        for(int i = 0; i %3C len; i++)%7B%0A        %09if(path.charAt(i) == '/') continue;%0A%0A        %09int j = i + 1;%0A%0A        %09while(j %3C len && path.charAt(j) != '/')%7B%0A                j++;%0A            %7D%0A            String tempString = path.substring(i, j);%0A%0A            j--;%0A            i = j;%0A        %09list.add(tempString);%0A        %7D%0A%0A        Stack%3CString%3E st = new Stack%3CString%3E();%0A%0A        for(String s : list)%7B%0A        %09if(st.isEmpty())%7B%0A        %09%09if(s.equals(%22.%22) %7C%7C s.equals(%22..%22)) continue;%0A        %09%09st.push(s);%0A        %09%7Delse if(s.equals(%22.%22))%7B%0A        %09%09continue;%0A        %09%7Delse if(s.equals(%22..%22))%7B%0A        %09%09st.pop();%0A        %09%7Delse%7B%0A        %09%09st.push(s);%0A        %09%7D%0A        %7D%0A%0A        if(st.isEmpty())%7B%0A        %09return %22/%22;%0A        %7D%0A%0A        StringBuilder sb = new StringBuilder();%0A%0A        for(String s : st)%7B%0A        %09sb.append(%22/%22 + s);%0A        %7D%0A%0A        return sb.toString();%0A    %7D%0A%7D%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A

add simplify path solution