6 lines Python code, simple and fast

  • 0
    def encode(self, strs):
        if not strs:
            return None
        return ' * '.join([x.replace("*", "**") for x in strs])
    def decode(self, s):
        if s == None:
            return []
        return [x.replace("**", "*") for x in s.split(" * ")]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.