377 Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.
Example:
Follow up: What if negative numbers are allowed in the given array? How does it change the problem? What limitation we need to add to the question to allow negative numbers?
这题跟backpackVI是一样的,主要不同是follow up。follow up的解释请参照:http://xyma.me/2016/12/13/Combination-Sum-IV/
允许负数或0的话,会导致出现无限多的结果,因为多加一个0 或者一对+a,-a,不会影响和的大小。解决方案只能限制return值的长度。
Last updated