如果我有一个任意长度的数组。如果知道每个切片的元素数量,我怎么能找到该数组的给定元素的偏移量?我的意思是没有实际切片阵列。确定数组中偏移量的最快方法
例子:
arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ..n]
if perSlice = 4; offset for arr[5] == 1, for arr[8] == 2 etc.
if perSlice = 3; offset for arr[2] = 0, for arr[4] = 1 etc.
i.e.:
perSlice = 4
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ..n]
0 0 0 0 1 1 1 1 2 2 2, ..n
有趣.... – Agzam 2014-09-19 09:47:36
用代码更新以生成你想要的数组(我理解它) – AlexanderBrevig 2014-09-19 09:53:18
不需要生成数组。它只是为了更好地解释我需要的东西。谢谢 – Agzam 2014-09-19 09:58:48