Leetcode 377 combination sum iv
sparshgarg23 opened this issue · 1 comments
sparshgarg23 commented
Hi,I was running your solution for the above mentioned problem.It seems that if we create a vector of integers to represent then we get the following error:
"Runtime error signed integer overflow <large number addition cannot be represented by int?
The error goes away if we use unsigned integer representation.
Also can you please explain the logic behind the solution
kamyu104 commented
- Thanks for your reminding.
- We denote the number of possible combinations that adding up to the positive integer i as dp[i].
- The idea is to get dp[i] of i from 0 to target.
- For each dp[i], we can get dp[i] by sum(dp[i - num] for each num in nums and num <= i).
- Since dp[i] may exceed the max of int32_t, it is required to use uint32_t or uint64_t to count the number based on the input range.