小编Zol*_*asi的帖子

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]);
        });

        // …
Run Code Online (Sandbox Code Playgroud)

javascript

8
推荐指数
1
解决办法
2523
查看次数

标签 统计

javascript ×1