public class RainbowSocks
{
public double getPairProb(int[] socks, int colordiff)
{
int len = socks.length;
int total = len * (len - 1) / 2;
int cnt = 0;
for (int i = 0; i < len; i++)
{
for (int j = i + 1; j < len; j++)
{
if (Math.abs(socks[i] - socks[j]) <= colordiff)
{
cnt++;
}
}
}
return (double)cnt/ total;
}
}
TCO17 Austin RainbowSocks
最新推荐文章于 2020-02-23 17:13:10 发布