Skip to content

Commit 604050c

Browse files
committed
Simpli solution of SimplifyPath task
1 parent df893fe commit 604050c

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/main/java/by/andd3dfx/collections/SimplifyPath.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.ArrayDeque;
44
import java.util.Deque;
5-
import java.util.List;
65

76
/**
87
* <pre>
@@ -67,23 +66,17 @@ public static String simplifyPath(String path) {
6766
var chars = path.toCharArray();
6867
var i = 1;
6968
while (i < chars.length) {
70-
switch (chars[i]) {
71-
case '/':
72-
processAccumulated(accumulator, stack);
73-
accumulator = new StringBuilder();
74-
break;
75-
76-
default:
77-
accumulator.append(chars[i]);
69+
if (chars[i] == '/') {
70+
processAccumulated(accumulator, stack);
71+
accumulator = new StringBuilder();
72+
} else {
73+
accumulator.append(chars[i]);
7874
}
7975
i++;
8076
}
8177
processAccumulated(accumulator, stack);
8278

83-
List<String> folders = stack.stream()
84-
.toList()
85-
.reversed();
86-
return "/" + String.join("/", folders);
79+
return "/" + String.join("/", stack.reversed());
8780
}
8881

8982
private static void processAccumulated(StringBuilder accumulator, Deque<String> stack) {

0 commit comments

Comments
 (0)