救命!我的某些数组中似乎有一个令人讨厌的回声,我想摆脱它。发生这种情况时,原始数组会在中间的某个位置重复自身,从而使这些值彼此相加。
例如,数组[ 422, 375, 527, 375, 859, 451, 754, 451 ]
包含自身的回声,如下所示:
[ 422, 375, 527, 375, 859, 451, 754, 451 ] <-- array with echo (input)
[ 422, 375, 105, 0, 754, 451 ] <-- original array (output)
[ 422, 375, 105, 0, 754, 451 ] <-- echo of original array
范例2:
[ 321, 526, 1072, 899, 6563, 798, 7038, 3302, 3032, 3478, 1806, 601 ] <-- input
[ 321, 526, 751, 373, 5812, 425, 1226, 2877, 1806, 601 ] <-- output
[ 321, 526, 751, 373, 5812, 425, 1226, 2877, 1806, 601 ]
数组中也可能没有回声,在这种情况下,将返回原始数组:
范例3:
[ 623, 533, 494, 382 ] <-- input
[ 623, 533, 494, 382 ] <-- output
挑战:
给定一个可能包含回声的数组,请将其删除并返回没有回声的数组。
输入:
- 阵列,列表,分隔的字符串,打孔卡或平台-合适当量,含有三个或更多个整数,在范围与至少一种元素。
- 回声不能在第一个元素或最后一个元素之后开始。
- 回声将在输入中仅出现一次或完全不出现。
输出:
- 阵列,列表,整数等,与回波除去。
- 如果没有回声,则返回原始数组。
规则和评分:
测试用例:
有回声:
[ 422, 375, 527, 375, 859, 451, 754, 451 ]
[ 422, 375, 105, 0, 754, 451 ]
[ 321, 526, 1072, 899, 6563, 798, 7038, 3302, 3032, 3478, 1806, 601 ]
[ 321, 526, 751, 373, 5812, 425, 1226, 2877, 1806, 601 ]
[ 4330, 3748, 363, 135, 2758, 3299, 1674, 1336, 4834, 2486, 4087, 1099, 4098, 4942, 2159, 460, 4400, 4106, 1216, 3257, 1638, 2848, 3616, 3554, 1605, 490, 1308, 2773, 3322, 3284, 4037, 7109, 4171, 5349, 2675, 3056, 4702, 4229, 1726, 5423, 6039, 8076, 6047, 7088, 9437, 4894, 1946, 7501, 5331, 3625, 5810, 6289, 2858, 6610, 4063, 5565, 2200, 3493, 4573, 4906, 3585, 4147, 3748, 3488, 5625, 6173, 3842, 5671, 2555, 390, 589, 3553, 3989, 4948, 2990, 4495, 2735, 1486, 3101, 1225, 2409, 2553, 4651, 10, 2994, 509, 3960, 1710, 2185, 1800, 1584, 301, 110, 969, 3065, 639, 3633, 3544, 4268 ]
[ 4330, 3748, 363, 135, 2758, 3299, 1674, 1336, 4834, 2486, 4087, 1099, 4098, 4942, 2159, 460, 4400, 4106, 1216, 3257, 1638, 2848, 3616, 3554, 1605, 490, 1308, 2773, 3322, 3284, 4037, 2779, 423, 4986, 2540, 298, 1403, 2555, 390, 589, 3553, 3989, 4948, 2990, 4495, 2735, 1486, 3101, 1225, 2409, 2553, 4651, 10, 2994, 509, 3960, 1710, 2185, 1800, 1584, 301, 110, 969, 3065, 639, 3633, 3544, 4268 ]
[ 24, 12, 52, 125, 154, 3, 567, 198, 49, 382, 53, 911, 166, 18, 635, 213, 113, 718, 56, 811, 67, 94, 80, 241, 343, 548, 68, 481, 96, 79, 12, 226, 255, 200, 13, 456, 41 ]
[ 24, 12, 52, 125, 154, 3, 567, 198, 25, 370, 1, 786, 12, 15, 68, 15, 88, 348, 55, 25, 55, 79, 12, 226, 255, 200, 13, 456, 41 ]
[ 1, 3, 2 ]
[ 1, 2 ]
[ 0, 1, 3, 2, 0 ]
[ 0, 1, 2, 0 ]
没有回声:
[ 623, 533, 494, 382 ]
[ 623, 533, 494, 382 ]
[ 1141, 1198, 3106, 538, 3442, 4597, 4380, 3653, 1370, 3987, 1964, 4615, 1844, 5035, 2463, 6345, 4964, 4111, 5192, 8555, 5331, 3331, 4875, 6586, 5728, 4532, 5972, 2305, 3491, 6317, 2256, 2415, 5788, 4873, 6480, 2080, 5319, 4551, 6527, 5267, 4315, 2178, 2615, 5735, 5950, 6220, 7114, 6259, 5000, 4183, 6822, 6927, 7150, 8003, 5603, 3154, 8231, 5005, 5743, 6779, 4530, 4029, 5336, 6105, 4777, 6183, 6838, 5725, 6819, 8584, 3142, 3840, 3291, 4284, 2933, 4859, 2906, 5176, 2853, 2110, 2048, 4389, 4501, 2267, 2704, 431, 1495, 2712, 3008, 187, 3487, 630 ]
[ 1141, 1198, 3106, 538, 3442, 4597, 4380, 3653, 1370, 3987, 1964, 4615, 1844, 5035, 2463, 6345, 4964, 4111, 5192, 8555, 5331, 3331, 4875, 6586, 5728, 4532, 5972, 2305, 3491, 6317, 2256, 2415, 5788, 4873, 6480, 2080, 5319, 4551, 6527, 5267, 4315, 2178, 2615, 5735, 5950, 6220, 7114, 6259, 5000, 4183, 6822, 6927, 7150, 8003, 5603, 3154, 8231, 5005, 5743, 6779, 4530, 4029, 5336, 6105, 4777, 6183, 6838, 5725, 6819, 8584, 3142, 3840, 3291, 4284, 2933, 4859, 2906, 5176, 2853, 2110, 2048, 4389, 4501, 2267, 2704, 431, 1495, 2712, 3008, 187, 3487, 630 ]
[ 4791, 1647, 480, 3994, 1507, 99, 61, 3245, 2932, 8358, 6618, 1083, 5391, 3498, 4865, 1441, 3729, 5322, 5371, 6271, 2392, 1649, 5553, 9126, 3945, 2179, 3672, 2201, 4433, 5473, 4924, 6585, 6407, 3862, 6505, 1530, 5293, 4792, 6419, 6739, 3258, 3839, 3891, 7599, 2576, 5969, 5659, 6077, 5189, 1325, 4490, 5694, 6567, 6367, 5724, 5756, 6450, 5863, 4360, 2697, 3100, 3779, 4040, 4653, 1755, 3109, 2741, 3269 ]
[ 4791, 1647, 480, 3994, 1507, 99, 61, 3245, 2932, 8358, 6618, 1083, 5391, 3498, 4865, 1441, 3729, 5322, 5371, 6271, 2392, 1649, 5553, 9126, 3945, 2179, 3672, 2201, 4433, 5473, 4924, 6585, 6407, 3862, 6505, 1530, 5293, 4792, 6419, 6739, 3258, 3839, 3891, 7599, 2576, 5969, 5659, 6077, 5189, 1325, 4490, 5694, 6567, 6367, 5724, 5756, 6450, 5863, 4360, 2697, 3100, 3779, 4040, 4653, 1755, 3109, 2741, 3269 ]
[ 235, 121, 52, 1249, 154, 26, 5672, 1975, 482, 3817, 532, 9104, 1661, 171, 6347, 2124, 1122, 7175, 558, 8101, 667, 934, 798, 2404, 3424, 5479, 672, 4808, 956, 789, 123, 2255, 2549, 200, 126, 4562, 41 ]
[ 235, 121, 52, 1249, 154, 26, 5672, 1975, 482, 3817, 532, 9104, 1661, 171, 6347, 2124, 1122, 7175, 558, 8101, 667, 934, 798, 2404, 3424, 5479, 672, 4808, 956, 789, 123, 2255, 2549, 200, 126, 4562, 41 ]
[ 1, 1, 1, 1, 1 ]
[ 1, 1, 1, 1, 1 ]
[1, 2, 3, 1, 2, 3]
,[1, 2, 3, 0, 1, 2, 3]
,[0, 1, 3, 2, 0]
?当前的答案在所有这些输入上并不一致。
[1, 1, 1, 1]
与[1, 2, 1]
)中的任何一个都是可以接受的。我最初有一个选择规则,但由于它似乎仅适用于少数边缘情况,因此在沙盒中取消了选择。
[0, 1, 3, 2, 0]
应该是[0, 1, 2, 0]
-我已添加到测试用例中。[1, 2, 3]
尽管根据规则我不会考虑那些有效的测试用例,但对另外两个的预期答案可能是the original array repeats itself somewhere in the middle
。
[0,0,0]
(或任何大小的all- 0
的数组)代表任何东西的回声还是[0,0,0]
(对于任何特殊情况)(无回声)是否也都是有效答案都是模棱两可的,因为没有足够的信息来确定哪个它是。我将更新规则以限制其为有效输入,因为这不会使任何现有答案无效或改变。
[1, 2, 2, 2, 1]
; 输出:[1, 1, 1, 1]
vs[1, 2, 1]