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.
1 parent d184bef commit b02e135Copy full SHA for b02e135
encode-and-decode-strings/EcoFriendlyAppleSu.kt
@@ -0,0 +1,33 @@
1
+package leetcode_study
2
+
3
+/*
4
+* 문자열 인코딩 디코딩 문제
5
+* 시간 복잡도: O(n)
6
+* 공간 복잡도: O(n)
7
+* */
8
+fun encoding(strs: List<String>): String {
9
+ var result = ""
10
+ if (strs.isEmpty()) return result
11
+ for (index in 0 until strs.size - 1) {
12
+ if (strs[index] == ":") {
13
+ result += strs[index] + "::;"
14
+ } else {
15
+ result += strs[index] + ":;"
16
+ }
17
18
+ result += strs[strs.size - 1]
19
+ return result
20
+}
21
22
+fun decoding(str: String): List<String>{
23
+ val splitedStrList = str.split(":;")
24
+ val result = mutableListOf<String>()
25
+ for (splitStr in splitedStrList){
26
+ if (splitStr == "::") {
27
+ result.add(":")
28
29
+ result.add(splitStr)
30
31
32
33
0 commit comments