本题未写代码,只写了注释,练一下英语。
* float values in an array, get the max subtraction between 2 adjacent items by value(not by index).
** Be careful, O(n) and O(n)
*
* 1) find the min and max, get the v1 = floor(min) and v2 = ceiling(max).
* 2) new buckets between v1 and v2, interval is 1.
* 3) go through array and mark the buckets, if bucket is not empty, it is 1, else 0.
* 4) go through buckets, find the 2 buckets A and B that qualify :
* a) both not empty
* b) interval buckets are all empty.
* c) length of interval buckets is longest.
* d) if all items in only one bucket, it means A==B, keep going same steps below.
* 5) go through array, find the item in A which is max.
* 6) go through array, find the item in B which is min.
* 7) get their subtraction, that it is.
本文介绍一种算法思路,用于找出数组中两个相邻浮点数值间的最大差值。该算法通过查找数组中的最小值与最大值,并利用桶排序的思想来实现O(n)的时间复杂度。
168万+

被折叠的 条评论
为什么被折叠?



