Question:
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.
Machine 1 (sender) has the function:
Machine 2 (receiver) has the function:
So Machine 1 does:
and Machine 2 does:
strs2 in Machine 2 should be the same as strs in Machine 1.
Implement the encode and decode methods.
Note:
- The string may contain any possible characters out of 256 valid ascii characters. Your algorithm should be generalized enough to work on any possible characters.
- Do not use class member/global/static variables to store states. Your encode and decode algorithms should be stateless.
- Do not rely on any library method such as eval or serialize methods. You should implement your own encode/decode algorithm.
Explanation:
乍一看,也不知道说的是什么。其实题意是给一个list的字符串,先要拼成一整个字符串,是encode。然后把这整个字符拆回一个list的字符。
所以考点是如何合理地分隔,然后还能识别出来。
这哪儿是算法,其实考的是Serilization这个计算机系统中的基本概念。