public static String simplifyPath(String A) {
String path="";
String temp[] = A.split("/");
MyStack stack = new MyStack(temp.length);
for(int i=1;i<temp.length;i++) {
if(!temp[i].equals("") && !temp[i].equals(".")) {
if(temp[i].equals("…") ) {
if(!stack.isEmpty()) {
stack.pop();
}
}else {
stack.push(temp[i]);
}
}
}
if(stack.isEmpty()) {
return “/”;
}
while(!stack.isEmpty()) {
path = stack.pop()+"/"+path;
}
return “/”+path.substring(0,path.length()-1);
}
class MyStack{
String[] array;
int top = -1;
public MyStack(int n) {
array = new String[n];
}
public void push(String s) {
if(top==array.length-1) {
return;
}
array[++top] = s;
}
public String pop() {
if(isEmpty()) {
return null;
}
return array[top--];
}
public boolean isEmpty() {
if(top == -1)
return true;
else
return false;
}
}