【发布时间】:2020-09-03 02:06:14
【问题描述】:
我一直在尝试解决这个挑战,但我找不到解决方法。我以前解决过类似的问题,但我发现这特别困难,甚至试图在保持线性时间复杂度的同时解决。这是我显然失败的面试评估的一部分。
我将不胜感激。 谢谢
挑战来了
You are to parse the string into pieces that are no more than "pieceLength" characters long
INCLUDING the commas.
If pieceLength = 3 the result for the above test string would be
result[0] = "1,2"
result[1] = ",3,"
result[2] = "5,8"
result[3] = ","
result[4] = "131"
result[5] = ",21"
result[6] = ",34"
You can look at the test above. This is a sample string and result, however
your code will be run with multiple input strings and piece length parameters.
Note how result[3] is just ",". Including any more characters would break apart
the next number, 131, and that's not allowed.
【问题讨论】:
-
对不起,我忘了放原始字符串。目标是将这个“1,2,3,5,8,131,21,34”解析为上述数组。
标签: arrays string parsing split