题目描述:
给出一个整数列表,找出该列表无法通过各种组合求和得到的最小的整数。
示例:
solve([1,2,8,7]) = 4, because we can get 1, 2, 1+2=3. But 4 is the minimum number not possible from the list. solve([4,2,12,3,1]) = 11. We have 1, 2, 3, 4, 4+1=5, 4+2=6, 4+3=7,4+3+1=8,4+3+2=9,4+3+2+1=10. But no 11. solve([4,2,12,3]) = 1
最佳解答:
虽然对该答案理解的不够透彻,但是这是感觉速度最快的。
def solve(xs): m = 0 for x in sorted(xs): if x > m + 1: break m += x return m + 1