class Solution:
def encode(self, strs: List[str]) -> str:
res = ""
for s in strs:
res += str(len(s)) + "#" + s
return res
def decode(self, s: str) -> List[str]:
res = []
i = 0
while i < len(s):
j = i
while s[j] != '#':
j += 1
length = int(s[i:j])
i = j + 1
j = i + length
res.append(s[i:j])
i = j
return res
PythonError: Traceback (most recent call last):
File "/lib/python313.zip/_pyodide/_base.py", line 513, in eval_code
CodeRunner(
~~~~~~~~~~^
source,
^^^^^^^
...<5 lines>...
optimize=optimize,
^^^^^^^^^^^^^^^^^^
)
^
File "/lib/python313.zip/_pyodide/_base.py", line 285, in __init__
self.ast = next(self._gen)
~~~~^^^^^^^^^^^
File "/lib/python313.zip/_pyodide/_base.py", line 149, in _parse_and_compile_gen
mod = compile(source, filename, mode, flags | ast.PyCF_ONLY_AST)
File "<exec>", line 62
_candidate =
^
SyntaxError: invalid syntax
When I get to
271. Encode and Decode Strings, The Code section doesn't contain a template to build from. If I copy the following solution in and try to test it:I get: