Skip to content

Encode and Decode Strings Code section missing template, evaluation fails with error #2

Description

@benwbooth

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:

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

I get:

 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions