We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 01e0bae commit a7790ffCopy full SHA for a7790ff
1 file changed
encode-and-decode-strings/kangdaia.py
@@ -0,0 +1,37 @@
1
+class Solution:
2
+ def encode(self, strs: list[str]) -> str:
3
+ """
4
+ 인코딩 함수
5
+ 방식: %를 사용해 문자열의 길이 + % + 문자열로 인코딩
6
+
7
+ Args:
8
+ strs (list[str]): 인코딩할 문자열 목록
9
10
+ Returns:
11
+ str: 인코딩된 문자열
12
13
+ return "".join(f"{len(s)}%{s}" for s in strs)
14
15
+ def decode(self, s: str) -> list[str]:
16
17
+ 디코딩 함수
18
+ 시간복잡도: O(N)
19
20
21
+ s (str): 디코딩할 문자열
22
23
24
+ list[str]: 디코딩된 문자열 목록
25
26
+ res = []
27
+ i = 0
28
+ while i < len(s):
29
+ j = i
30
+ while s[j] != "%":
31
+ j += 1
32
+ length = int(s[i:j])
33
+ start = j + 1
34
+ end = start + length
35
+ res.append(s[start:end])
36
+ i = end
37
+ return res
0 commit comments