给定一组元素,如何找到该列表的所有子集中最大值和最小值之间的差异。
例如:
set = 1 2 3
Subset = {1}, max(s)-min(s) = 0.
Subset = {2}, max(s)-min(s) = 0.
Subset = {3}, max(s)-min(s) = 0.
Subset = {1,2}, max(s)-min(s) = 1.
Subset = {2,3}, max(s)-min(s) = 1.
Subset = {1,3}, max(s)-min(s) = 2.
Subset = {1,2,3}, max(s)-min(s) = 2.
So the output will be 1+1+2+2 = 6
O(nlogn)
。但是,映射上的常数会更糟,因为数组要简单得多。 - amit