leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0377.cpp (335B)


      1 class Solution {
      2   public:
      3     int combinationSum4(vector<int> &nums, int target) {
      4         vector<long long> dp(target + 1, 0);
      5         dp[0] = 1;
      6 
      7         for (int i = 1; i <= target; i++)
      8             for (int num : nums)
      9                 if (i - num >= 0) dp[i] = (dp[i] + dp[i - num]) % INT_MAX;
     10 
     11         return dp.back();
     12     }
     13 };