小编Hen*_*odi的帖子

如何减少两个for循环的大O复杂度

该函数必须返回数组中数字对的计数songs(整数数组,包括以秒为单位的歌曲长度),这样形成的对数加起来整整几分钟.

long playlist(int songs_count, int *songs) {
    int i, j, k = 0;
    for (i = 0; i < songs_count; i++) {
        for (j = i + 1; j < songs_count; j++)
            if ((songs[i] + songs[j]) % 60 == 0)
                k++;
    }
    return k;
}
Run Code Online (Sandbox Code Playgroud)

c big-o asymptotic-complexity

2
推荐指数
1
解决办法
421
查看次数

标签 统计

asymptotic-complexity ×1

big-o ×1

c ×1