这是问题的链接:
https://codility.com/demo/take-sample-test/clocks
问题是我不能得到100分(只有42分).运行时间没问题,但是对于某些测试用例,代码给出了错误的答案,但我无法弄清楚问题是什么.有人可以帮帮我吗?
这是我的代码:
function rotate(arr) {
var min = arr.reduce(function(a,b) { return a > b ? b : a });
while (arr[0] != min) {
var first = arr.shift();
arr.push(first);
}
}
function solution(A, P) {
var positions = [];
A.forEach(function(clock) {
var position = [];
clock.sort(function(a, b) { return a - b });
clock.push(clock[0] + P);
// calculating the distances between clock hands
clock.forEach(function(hand, idx) {
if (idx == 0) return;
position.push(clock[idx] - clock[idx - 1]);
});
// …
Run Code Online (Sandbox Code Playgroud) javascript ×1