年轻人不讲码得用sort来偷袭

年轻人不讲码得用sort来偷袭

Mapleleave · 发布于 2021-04-13 · 浏览 627 回复 1
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 条

  1. 前500题=入门省一 #1 ·

    用sort,时间复杂度也是nlogn。 时间复杂度一样,只是代码看起来短一点。

发表回复