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 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