Given a set of numbers, divide the numbers into two subsets such that difference between the sum of numbers in two subsets is minimal.
This is the idea that I have, but I am not sure if this is a correct solution:
- Sort the array
- Take the first 2 elements. Consider them as 2 sets (each having 1 element)
- Take the next element from the array.
- Decide in which set should this element go (by computing the sum => it should be minimum)
- Repeat
Is this the correct solution? Can we do better?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…