如果给我三个相等长度的数组。每个阵列代表到特定景点的距离(即,第一个阵列仅是主题公园,第二个阵列仅是博物馆,第三个阵列仅是海滩),这是我要参加的公路旅行的距离。我不会确定所有可能的旅行都在每次旅行中的每种吸引力中的一种停止,永不向后行驶,也永远不会两次访问相同的吸引力。
IE浏览器,如果我有以下三个数组:[29 50] [61 37] [37 70]
该函数将返回3,因为可能的组合为:(29,61,70)(29,37,70)(50,61,70)
到目前为止,我得到的是:public int test(int [] A,int [] B,int [] C){
int firstStop = 0;
int secondStop = 0;
int thirdStop = 0;
List<List<int>> possibleCombinations = new List<List<int>>();
for(int i = 0; i < A.Length; i++)
{
firstStop = A[i];
for(int j = 0; j < B.Length; j++)
{
if(firstStop < B[j])
{
secondStop = B[j];
for(int k = 0; k < C.Length; k++)
{
if(secondStop < C[k])
{
thirdStop = C[k];
possibleCombinations.Add(new List<int>{firstStop, secondStop, thirdStop});
}
}
}
}
}
return possibleCombinations.Count();
}
这适用于以下测试用例:
测试示例:([[29,50],[61,37],[37,70])OK返回3
测试示例:([5],[5],[5])OK返回0
测试示例:([[61,62],[37,38],[29,30])FAIL返回0
什么是正确计算此算法的正确算法?什么是性能最好的算法?
我如何分辨该算法的时间复杂度(即O(N * log(N)))的性能?
慕后森
相关分类