Working solution to the problem


#1
import java.util.stream.Collectors;

public class Solution {
public String simplifyPath(String A) {
String[] arr = A.split("/");
Stack ps = new Stack<>();
for (String dir : arr) {
if (dir.trim().isEmpty() || dir.equals(".")) {
continue;
} else if (dir.equals("…")) {
if(!ps.isEmpty())
ps.pop();
} else {
ps.push(dir);
}
}
List path = new ArrayList<>();
while (!ps.isEmpty()) {
path.add(0, ps.pop());
}
return path.stream().collect(Collectors.joining("/", “/”, “”));
}
}