C# DP like back pack or climb stair question


  • 0
    Y
    public class Solution {
        public int CombinationSum4(int[] nums, int target) {
            //DP
            int[] DP=new int[target+1];
            DP[0]=1;
            for(int i=1;i<=target;i++)
            {
                for(int j=0;j<nums.Length;j++)
                {
                    if(i-nums[j]>=0)
                        DP[i] += DP[i-nums[j]];
                }
            }
            return DP[target];
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.