题目说明
编写 function solution(tokens, size, overlap)。输入输出均为 JSON 值,不要修改输入数组或对象。不支持外部库、网络访问及异步函数。 tokens:JSON[], size:integer 1–1024, overlap:integer 0<=overlap<size. Start at 0 and advance by size-overlap. Each chunk is {start,end,tokens}, with end=min(length,start+size) exclusive. Stop immediately after a chunk reaches the input end. Empty input yields []. Preserve JSON tokens without joining or string conversion. 输入范围:每个输入数组最多50,000项,每个字符串最多1,000个字符。数字必须有限,整数及整数累计结果在JavaScript安全整数范围内。其他类型和有效性遵循上述规则。
输入输出示例
示例 1
函数参数
[
[
"a",
"b",
"c",
"d",
"e"
],
3,
1
]返回值
[
{
"start": 0,
"end": 3,
"tokens": [
"a",
"b",
"c"
]
},
{
"start": 2,
"end": 5,
"tokens": [
"c",
"d",
"e"
]
}
]示例 2
函数参数
[
[
"a",
"b",
"c",
"d"
],
2,
0
]返回值
[
{
"start": 0,
"end": 2,
"tokens": [
"a",
"b"
]
},
{
"start": 2,
"end": 4,
"tokens": [
"c",
"d"
]
}
]示例 3
函数参数
[
[
null,
true
],
3,
0
]返回值
[
{
"start": 0,
"end": 2,
"tokens": [
null,
true
]
}
]