Encode and decode string
July 18, 2022
array-and-hashmapProblem URL: Encode and decode string
We will join the array using $$
as delimeter, and also split the string with $$
to get it back.
from typing import List
class Solution:
def encode(self, s: List[str]) -> str:
return '$$'.join(s)
def decode(self, s: str) -> List[str]:
return s.split('$$')
Time Complexity: O(n), where n is the length of the array
Space Complexity: O(1)