import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param path string字符串
* @return string字符串
*/
public String simplifyPath (String path) {
// write code here
String[] strs = path.split("/");
Stack<String> stack = new Stack<>();
for (String str: strs) {
if (str.equals("..")) {
if (!stack.isEmpty()) {
stack.pop();
}
}
else if (!(str.equals(".") || str.equals(""))) {
stack.push(str);
}
}
String res = "";
while (!stack.isEmpty()) {
res = "/" + stack.pop() + res;
}
return res.length() == 0 ? "/" : res;
}
}