int maximumGap(int a,double x[])
{
sort(x, x + a);
for (int i = 0; i < a - 1; i++)
d[i] = x[i + 1] - x[i];
sort(d, d + a - 1);
cout.setf(ios::fixed);
cout << fixed << setprecision(2) << d[a - 2] << endl;
return 0;
}
全部回复 共 1 条
-
用sort,时间复杂度也是nlogn。 时间复杂度一样,只是代码看起来短一点。
发表回复
登录后即可回复本帖,与出题人和同学一起讨论。
登录