Skip to content

Commit 4c9d64a

Browse files
author
王俊超
committed
commit
1 parent 2cff2ea commit 4c9d64a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.util.LinkedList;
2+
import java.util.List;
3+
4+
/**
5+
* @author: wangjunchao(王俊超)
6+
* @time: 2018-09-28 15:50
7+
**/
8+
public class Solution {
9+
public String simplifyPath(String path) {
10+
String[] ss = path.split("/");
11+
List<String> result = new LinkedList<>();
12+
13+
for (String part : ss) {
14+
if (".".equals(part)) {
15+
continue;
16+
} else if ("..".equals(part)) {
17+
if (result.size() > 0) {
18+
result.remove(result.size() - 1);
19+
}
20+
} else if (!"".equals(part.trim())) {
21+
result.add(part);
22+
}
23+
}
24+
25+
StringBuilder builder = new StringBuilder();
26+
for (String part : result) {
27+
builder.append("/").append(part);
28+
}
29+
30+
return builder.length() == 0 ? "/" : builder.toString();
31+
}
32+
}

0 commit comments

Comments
 (0)