여기에 문제에 대한 링크의 회전 할 때 동일한 보면 손으로 시계의 최대 수를 찾기 :Codility 교육 :
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]);
});
// rotating the distances array to start with the minimum element
rotate(position);
positions.push(position);
});
//lexicographically sort positions array to similar types be consecutive
positions.sort();
var sum = 0;
// create a string to compare types with each other
var type = positions[0].join(",");
var n = 0;
// counting consecutive positions with same type
positions.forEach(function(position, idx) {
if (type == position.join(",")) {
n++;
} else {
type = position.join(",");
sum += (n * (n-1))/2;
n = 1;
}
});
sum += (n * (n-1))/2;
return sum;
}
테스트 사례는 무엇입니까? 예상되는 출력과 잘못된 출력은 무엇입니까? – geoffspear
코드얼리티가 정확한 테스트 케이스를 제공하지 않기 때문에 잘 모르겠습니다. 나는 실패한 것을 만들 수 없다. –
다음은 codility 출력입니다. https://codility.com/demo/results/demoXRF8PS-JWG/ –