We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9c743c6 + 63d4698 commit bf55435Copy full SHA for bf55435
level-2/[3차]-압축&17684&.js
@@ -31,3 +31,25 @@ function solution(msg) {
31
}
32
return outputs;
33
34
+
35
+// 정답 2 - ssi02014
36
+function solution(msg) {
37
+ const result = [];
38
+ const dict = Array.from({length: 26},(_, i) => String.fromCharCode(65 + i))
39
40
+ // 시간 복잡도 O(N^2)
41
+ const lastWordAndCompression = msg.split("").reduce((acc, cur) => {
42
+ const nextWord = acc + cur;
43
+ const nextWordIdx = dict.indexOf(nextWord);
44
+ const prevWordIdx = dict.indexOf(acc);
45
46
+ if (nextWordIdx !== -1) return acc + cur;
47
+ dict.push(nextWord);
48
49
+ if (prevWordIdx !== -1) result.push(prevWordIdx + 1);
50
+ return cur;
51
+ }, "");
52
53
+ result.push(dict.indexOf(lastWordAndCompression) + 1);
54
+ return result;
55
+}
0 commit comments