Encode And Decode Strings

Medium
StringDesign

Encode and Decode Strings

Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.

Please implement encode and decode methods.

Example 1:

Input: ["lint","code","love","you"]
Output: ["lint","code","love","you"]
Explanation: One possible encode method is: "4#lint4#code4#love3#you"

Example 2:

Input: ["we", "say", ":", "yes"]
Output: ["we", "say", ":", "yes"]

Examples

Input: strs = ["Hello","World"]
Output: ["Hello","World"]
Input: strs = [""]
Output: [""]
Input: strs = []
Output: []

Constraints

  • 0 <= strs.length <= 200
  • 0 <= strs[i].length <= 200
  • strs[i] contains any possible characters.