public String simplifyPath(String path) {
        if (path == null || path.length() < 2) {
            return "/";
        }
        Stack<String> s = new Stack<String>();
        for(String p: path.split("/")) {
            if (p.length() == 0 || p.equals(".")) {
                continue;
            } else if (p.equals("..")) {
                if (!s.empty()) {
                    s.pop();
                }
            } else {
                s.push(p);
            }
        }
        if (s.empty()) {
            return "/";
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.size(); i ++) {
            sb.append("/").append(s.get(i));
        }
        return sb.toString();
    }