Pairwise Sum 算法follow up# JobHunting - 待字闺中
m*f
1 楼
常常见到的是给定sum, 找array中的pair, 现在变化一下
Given a list of numbers, A = {a0, a1, ..., an-1}, its pairwise sums P are
defined to be all numbers of the form ai + aj for 0 <= i < j < n. For
example, if
A = {1,2,3,4},
then
P = {1+2, 1+3, 1+4, 2+3, 2+4, 3+4} = {3, 4, 5, 5, 6, 7}.
Now give you P, design an algorithm to find all possible A.
Given a list of numbers, A = {a0, a1, ..., an-1}, its pairwise sums P are
defined to be all numbers of the form ai + aj for 0 <= i < j < n. For
example, if
A = {1,2,3,4},
then
P = {1+2, 1+3, 1+4, 2+3, 2+4, 3+4} = {3, 4, 5, 5, 6, 7}.
Now give you P, design an algorithm to find all possible A.